const int ledPins[] = {14, 15, 2, 0, 4, 16, 17}; // LED Pins
const int buttonPins[] = {27, 26, 25, 33, 32, 35, 34}; // Button Pins
const int numButtons = 7;
void setup() {
for (int i = 0; i < numButtons; i++) {
pinMode(ledPins[i], OUTPUT);
pinMode(buttonPins[i], INPUT_PULLUP); // Use internal pull-up resistors
}
}
void loop() {
int pressedButton = -1;
// Check which button is pressed, starting from highest priority
for (int i = 0; i < numButtons; i++) {
if (digitalRead(buttonPins[i]) == LOW) { // Button is pressed
pressedButton = i;
break; // Exit loop once the highest priority button is found
}
}
// Control LEDs based on the pressed button
for (int i = 0; i < numButtons; i++) {
if (i <= pressedButton) {
digitalWrite(ledPins[i], HIGH);
} else {
digitalWrite(ledPins[i], LOW);
}
}
}