int ledPins[] = {23, 22, 21, 19, 18, 5, 4, 2};
void setup() {
// Initialize each pin as an output:
for (int pin = 0; pin < 8; pin++) {
pinMode(ledPins[pin], OUTPUT);
}
}
void loop() {
// Move two LEDs from left to right:
for (int pin = 0; pin < 7; pin++) { // Stop at the second-to-last LED
digitalWrite(ledPins[pin], HIGH); // Turn the current LED on
digitalWrite(ledPins[pin + 1], HIGH); // Also turn the next LED on
delay(150); // Wait for 150 milliseconds
digitalWrite(ledPins[pin], LOW); // Turn the current LED off
}
digitalWrite(ledPins[7], LOW); // Ensure the last LED is turned off after the loop
// Pause at the end before moving back
delay(300);
// Move two LEDs from right to left:
for (int pin = 6; pin > 0; pin--) { // Start from the second-to-last LED
digitalWrite(ledPins[pin], HIGH); // Turn the current LED on
digitalWrite(ledPins[pin - 1], HIGH); // Also turn the previous LED on
delay(150); // Wait for 150 milliseconds
digitalWrite(ledPins[pin], LOW); // Turn the current LED off
}
digitalWrite(ledPins[0], LOW); // Turn off the first LED after finishing the loop to the left
// Pause at the end before restarting the animation
delay(300);
}