I am adapting a quiz program I had made before with 10 team buttons. Which worked fine, so I am sure the wiring is no issue here.
I am trying to setup button1 to be a “ready button” only after it is pressed and its light has lit up can the team buttons be pressed.
Currently the ready button presses and led lights up. Then I can press two of the team buttons which light up as well. And the program seems stuck in a loop I can’t do anything else. Any help is appreciated.
#include <ezButton.h>
const int teamCounter = 10; // Define the number of buttons and leds
const int ledPins[teamCounter] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; // Array of button pins (modify based on actual pins)
const int buttonPins[teamCounter] = {10, 11, 12, 13, A0, A1, A2, A3, A4, A5};
//Ready LED Pin 0
ezButton button1(10,INPUT_PULLUP);
ezButton resetBtn(11,INPUT_PULLUP);
ezButton button3(12,INPUT_PULLUP);
ezButton button4(13,INPUT_PULLUP);
ezButton button5(A0,INPUT_PULLUP);
ezButton button6(A1,INPUT_PULLUP);
ezButton button7(A2,INPUT_PULLUP);
ezButton button8(A3,INPUT_PULLUP);
ezButton button9(A4,INPUT_PULLUP);
ezButton button10(A5,INPUT_PULLUP);
int ledLock = 1;
unsigned long previousMillis = 0;
const long interval = 4000;
unsigned long currentMillis = 0;
int debounceTime = 10;
void setup() {
int ledLock = 1;
for (int i = 0; i < teamCounter; i++) {
pinMode(ledPins[i], OUTPUT);
}
resetBtn.setDebounceTime(debounceTime);
button2.setDebounceTime(debounceTime);
button3.setDebounceTime(debounceTime);
button4.setDebounceTime(debounceTime);
button5.setDebounceTime(debounceTime);
button6.setDebounceTime(debounceTime);
button7.setDebounceTime(debounceTime);
button8.setDebounceTime(debounceTime);
button9.setDebounceTime(debounceTime);
button10.setDebounceTime(debounceTime);
resetLEDs();
}
void loop() {
while (ledLock == 1) {
void resetLEDs();
resetBtn.loop();
if (resetBtn.isPressed()) {
digitalWrite(ledPins[0], LOW);
ledLock = 0;
}
}
while (ledLock == 0) {
loopButtons();
if (button2.isPressed() && ledLock == 0) {
ledLock = 1;
digitalWrite(ledPins[1], LOW); // Turn on corresponding LED
} else
if (button3.isPressed() && ledLock == 0) {
ledLock = 1;
digitalWrite(ledPins[2], LOW); // Turn on corresponding LED
} else
if (button4.isPressed() && ledLock == 0) {
ledLock = 1;
digitalWrite(ledPins[3], LOW); // Turn on corresponding LED
} else
if (button5.isPressed() && ledLock == 0) {
ledLock = 1;
digitalWrite(ledPins[4], LOW); // Turn on corresponding LED
} else
if (button6.isPressed() && ledLock == 0) {
ledLock = 1;
digitalWrite(ledPins[5], LOW); // Turn on corresponding LED
} else
if (button7.isPressed() && ledLock == 0) {
ledLock = 1;
digitalWrite(ledPins[6], LOW); // Turn on corresponding LED
} else
if (button8.isPressed() && ledLock == 0) {
ledLock = 1;
digitalWrite(ledPins[7], LOW); // Turn on corresponding LED
} else
if (button9.isPressed() && ledLock == 0) {
ledLock = 1;
digitalWrite(ledPins[8], LOW); // Turn on corresponding LED
}else
if (button10.isPressed() && ledLock == 0) {
ledLock = 1;
digitalWrite(ledPins[9], LOW); // Turn on corresponding LED
}
}
}
void loopButtons() {
if (ledLock == 1) {
// do nothing
} else {
button1.loop();
button3.loop();
button4.loop();
button5.loop();
button6.loop();
button7.loop();
button8.loop();
button9.loop();
button10.loop();
}
}
void resetLEDs() {
for (int i = 0; i < teamCounter; i++) {
digitalWrite(ledPins[i], HIGH);
// Turn off all LEDs
}
}
1