#define BUTTON_PIN 12 // Button connected to digital pin 12
#define LED_COUNT 10 // Total number of LEDs
int ledPins[LED_COUNT] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11}; // Array to hold LED pins
int currentLED = 0; // To track the current LED being lit
void setup() {
// Initialize LED pins as outputs
for (int i = 0; i < LED_COUNT; i++) {
pinMode(ledPins[i], OUTPUT);
}
// Initialize button pin
pinMode(BUTTON_PIN, INPUT_PULLUP); // Use internal pull-up resistor
}
void loop() {
// Read the button state
if (digitalRead(BUTTON_PIN) == LOW) { // Button pressed (active LOW)
// Turn off all LEDs first
for (int i = 0; i < LED_COUNT; i++) {
digitalWrite(ledPins[i], LOW);
}
// Turn on the current LED
digitalWrite(ledPins[currentLED], HIGH);
// Move to the next LED
currentLED++;
if (currentLED >= LED_COUNT) {
currentLED = 0; // Loop back to the first LED
}
// Short delay to debounce
delay(200);
}
}