int potpin = 0; // analog pin used to connect the potentiometer
int val; // variable to read the value from the analog pin
void setup() {
pinMode(9, OUTPUT);
}
void loop() {
val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)
val = map(val, 0, 1023, 0, 255); // scale it to use it with the light (value between 0 and 255)
analogWrite(9, val); // sets the LED brightness according to the scaled value
}