int potpin = 0;
int val; // variable to read the value from the analog pin
const int ledCount = 10;
int ledPins[] = {12,11,10,9,8,7,6,5,4,3}; // Added closing bracket
void setup() {
for (int thisLed = 0; thisLed < ledCount; thisLed++) {
pinMode(ledPins[thisLed], OUTPUT);
}
}
void loop() {
val = analogRead(potpin);
val = map(val, 0, 1023, 0, 10);
for (int i = 0; i < ledCount; i++) { // Loop to control LEDs
if (i < val) {
digitalWrite(ledPins[i], HIGH); // Turn on LEDs up to val
} else {
digitalWrite(ledPins[i], LOW); // Turn off LEDs beyond val
}
}
}