const int NUM_LEDS = 10;
const int LED_PINS[NUM_LEDS] = {13, 12, 11, 10, 9, 8, 7, 6, 5, 4};
int count = 0;
int increment = 1;
void setup() {
Serial.begin(115200);
for (int i = 0; i < NUM_LEDS; i++) {
pinMode(LED_PINS[i], OUTPUT);
}
}
void loop() {
int potVal = analogRead(A0);
int speed = map(potVal, 1023, 0, 100, 1000); // reverses pot
// turn all LEDs off
for (int i = 0; i < NUM_LEDS; i++) {
digitalWrite(LED_PINS[i], LOW);
}
// turn next LED on
digitalWrite(LED_PINS[count], HIGH);
count = count + increment;
if (count <= 0) increment = 1;
if (count >= (NUM_LEDS - 1)) increment = -1;
// wait a little
delay (speed);
}