// Define variables
int ledPins[] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11}; // An array to hold the LED pins
int buzzerPins[] = {A0, A1, A2, A3, A4, A5, A6, A7, A8, A9}; // An array to hold the buzzer pins
int buttonPins[] = {12, 13, 14, 15, 16, 17, 18, 19, 20, 21}; // An array to hold the button pins
int currentQuestion = 0; // The current question number
bool buttonPressed = false; // A flag to check if a button has been pressed
int buttonPressedIndex; // A variable to store the index of the pressed button
void setup() {
// Set the LED pins as outputs
for (int i = 0; i < 10; i++) {
pinMode(ledPins[i], OUTPUT);
}
// Set the buzzer pins as outputs
for (int i = 0; i < 10; i++) {
pinMode(buzzerPins[i], OUTPUT);
}
// Set the button pins as inputs
for (int i = 0; i < 10; i++) {
pinMode(buttonPins[i], INPUT_PULLUP);
}
// Set up Serial communication
Serial.begin(9600);
}
void loop() {
// Check if any button has been pressed
for (int i = 0; i < 10; i++) {
if (digitalRead(buttonPins[i]) == LOW) {
buttonPressed = true;
buttonPressedIndex = i;
break;
} else {
buttonPressed = false;
}
}
// If a button has been pressed, light up the corresponding LED and sound the buzzer
if (buttonPressed) {
digitalWrite(ledPins[buttonPressedIndex], HIGH);
tone(buzzerPins[buttonPressedIndex], 1000, 5000); // Sound the buzzer for 5 seconds
delay(5000); // Wait for 5 seconds
digitalWrite(ledPins[buttonPressedIndex], LOW);
}
}