const int ledPins[] = {13, 12, 11, 10};
const int numLeds = 4;
const int buttonPin = 2;
int buttonState = 0;
int lastButtonState = 0;
int clickCount = 0;
void setup() {
for (int i = 0; i < numLeds; i++) {
pinMode(ledPins[i], OUTPUT);
}
pinMode(buttonPin, INPUT);
}
void loop() {
buttonState = digitalRead(buttonPin);
if (buttonState != lastButtonState) {
if (buttonState == HIGH) {
clickCount++;
if (clickCount > numLeds + 1) {
clickCount = 1;
}
updateLeds();
}
delay(50);
}
lastButtonState = buttonState;
}
void updateLeds() {
for (int i = 0; i < numLeds; i++) {
if (i < clickCount && clickCount <= numLeds) {
digitalWrite(ledPins[i], HIGH);
} else {
digitalWrite(ledPins[i], LOW);
}
}
}