const int buttonPin = 2;
const int ledPin1 = 13;
const int ledPin2 = 8;
const int ledPin3 = 4;
bool buttonState = false;
void setup() {
// Set all LED pins as outputs
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
// Set button pin as input with internal pull-up resistor
pinMode(buttonPin, INPUT_PULLUP);
}
void loop() {
// Read the state of the button
buttonState = digitalRead(buttonPin);
// Check if the button is pressed
// (LOW means pressed when using INPUT_PULLUP connected to GND)
if (buttonState == LOW) {
digitalWrite(ledPin1, HIGH); // Turn LEDs on
digitalWrite(ledPin2, HIGH);
digitalWrite(ledPin3, HIGH);
} else {
digitalWrite(ledPin1, LOW); // Turn LEDs off
digitalWrite(ledPin2, LOW);
digitalWrite(ledPin3, LOW);
}
}