/* Analog Input Demonstrates analog input by reading an analog sensor on analog pin 3 (A3) and turning on and off a light emitting diode(LED) connected to digital/PWM pin 3. The amount of time the LED will be on and off depends on the value obtained by analogRead(). The circuit: * Potentiometer attached to analog input 3 (A3) * center pin of the potentiometer to the analog pin * one side pin (either one) to ground * the other side pin to +5V * LED anode (long leg) attached to digital/PWM output 3 * LED cathode (short leg) attached to ground */ int sensorPin = A3; // select the input pin for the potentiometer int ledPin = 3; // select the pin for the LED int sensorValue = 0; // variable to store the value coming from the sensor void setup() { // declare the ledPin as an OUTPUT: pinMode(ledPin, OUTPUT); } void loop() { // read the value from the sensor: sensorValue = analogRead(sensorPin); sensorValue = map(sensorValue,0,1023,0,255); //map scales ranges of numbers // brighten and dim LED analogWrite(ledPin, sensorValue); }