const int ledPins[4] = {2, 3, 4, 5}; // Array to store LED pin numbers
const int buttonPin = 8; // Push button pin number
int ledState = LOW; // Initial state of LEDs (OFF)
void setup() {
// Set LED pins as outputs
for (int i = 0; i < 4; i++) {
pinMode(ledPins[i], OUTPUT);
}
// Set button pin as input with internal pull-up resistor
pinMode(buttonPin, INPUT_PULLUP);
}
void loop() {
// Read button state (HIGH when not pressed, LOW when pressed)
int buttonState = digitalRead(buttonPin);
// Toggle LED state on button press (LOW to HIGH or HIGH to LOW)
if (buttonState == LOW && ledState == HIGH) {
ledState = LOW;
} else if (buttonState == HIGH && ledState == LOW) {
ledState = HIGH;
}
// Update all LEDs based on the current state
for (int i = 0; i < 4; i++) {
digitalWrite(ledPins[i], ledState);
}
}