const int buttonPin = 2;
const int ledPins[8] = {3, 4, 5, 6, 7, 8, 9, 10};
int currentLED = 0;
int lastButtonState = LOW;
int buttonState;
unsigned long lastDebounceTime = 0;
unsigned long debounceDelay = 50;
void setup() {
pinMode(buttonPin, INPUT);
for (int i = 0; i < 8; i++) {
pinMode(ledPins[i], OUTPUT);
digitalWrite(ledPins[i], LOW);
}
digitalWrite(ledPins[currentLED], HIGH);
}
void loop() {
int reading = digitalRead(buttonPin);
if (reading != lastButtonState) {
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > debounceDelay) {
if (reading != buttonState) {
buttonState = reading;
if (buttonState == HIGH) {
digitalWrite(ledPins[currentLED], LOW);
currentLED = (currentLED + 1) % 8;
digitalWrite(ledPins[currentLED], HIGH);
}
}
}
lastButtonState = reading;
}