const int numButtons = 3; // Number of buttons and LEDs
const int buttonPins[numButtons] = {22, 24, 26}; // Pins for buttons
const int ledPins[numButtons] = {23, 25, 27}; // Pins for LEDs
void setup() {
// Configure button pins as INPUT_PULLUP and LED pins as OUTPUT
for (int i = 0; i < numButtons; i++) {
pinMode(buttonPins[i], INPUT); // Set button pin with internal pull-up resistor
pinMode(ledPins[i], OUTPUT); // Set LED pin as output
digitalWrite(ledPins[i], LOW); // Ensure LEDs are off initially
}
}
void loop() {
for (int i = 0; i < numButtons; i++) {
// Read the button state (LOW when pressed, HIGH when not pressed)
int buttonState = digitalRead(buttonPins[i]);
if (buttonState == LOW) {
digitalWrite(ledPins[i], HIGH); // Turn LED on
} else {
digitalWrite(ledPins[i], LOW); // Turn LED off
}
}
}