// Define the total number of LEDs
const int NUM_LEDS = 8;
// Define the pin assignments for the LEDs (assuming 8 LEDs connected to digital pins 2 to 9)
const int LED_pins[] = {2, 3, 4, 5, 6, 7, 8, 9};
void setup() {
// Initialize LED pins as output
for (int i = 0; i < NUM_LEDS; i++) {
pinMode(LED_pins[i], OUTPUT);
}
}
void loop() {
// Sequentially turn on each LED with a one-second interval
for (int i = 0; i < NUM_LEDS; i++) {
// Turn on the current LED
digitalWrite(LED_pins[i], HIGH);
// Turn off the previously lit LED
if (i > 0) {
digitalWrite(LED_pins[i - 1], LOW);
}
// Delay for one second
delay(1000);
}
// Turn off the last LED after all LEDs have been lit
digitalWrite(LED_pins[NUM_LEDS - 1], LOW);
}