const int leds[] = {2, 3, 4, 5, 6, 7, 8, 9};
bool direction = true;
int currentLED = 0;
void setup() {
for (int i = 0; i < 8; i++) {
pinMode(leds[i], OUTPUT);
}
}
void loop() {
digitalWrite(leds[currentLED], HIGH);
delay(100);
digitalWrite(leds[currentLED], LOW);
if (direction) {
currentLED++;
if (currentLED == 7) {
direction = false;
}
} else {
currentLED--;
if (currentLED == 0) {
direction = true;
}
}
}