Listing 3. Fade an LED On/Off Using a Linear Potentiometer

/* Using potentiometer to fade on/off an LED
*  Original code notice below:
* ------------------------------
* Demonstrates analog input by reading an analog sensor on
* analog pin 0 and turning on and off a light emitting
* diode(LED) connected to digital pin 13.
* The amount of time the LED will be on and off
* depends on the value obtained by analogREAD().
* Created by David Cuartielles
* Modified 16 Jun 2009
* By Tom Igoe
* http://arduino.cc/en/Tutorial/AnalogInput
*/

int sensorPin = 0;
int ledPin = 13;
int sensorValue = 0;

void setup() {
     //declare the ledPin as an OUTPUT:
     pinMode(ledPin, OUTPUT);
     Serial.begin(9600);
}

void loop() {
        sensorValue = analogRead(sensorPin);//

        digitalWrite(ledPin, HIGH);

        delay(sensorValue);

        digitalWrite(ledPin, LOW);

        delay(sensorValue);
}