// Definición de pines
const int ledPins[] = {2, 3, 4, 5, 6}; // Pines de los LEDs
const int buttonPins[] = {7, 8, 9, 10, 11}; // Pines de los pulsadores
int currentLed = -1; // Variable para el LED actual
unsigned long startTime;
unsigned long gameTime = 60000; // Duración del juego: 1 minuto
void setup() {
// Configuración de los pines
for (int i = 0; i < 5; i++) {
pinMode(ledPins[i], OUTPUT);
pinMode(buttonPins[i], INPUT_PULLUP); // Configura los pulsadores con resistencia pull-up interna
digitalWrite(ledPins[i], HIGH); // Enciende todos los LEDs al inicio
}
}
void loop() {
// Comienzo del juego al presionar cualquier pulsador
if (currentLed == -1) {
for (int i = 0; i < 5; i++) {
if (digitalRead(buttonPins[i]) == LOW) {
startTime = millis(); // Inicia el tiempo de juego
currentLed = random(0, 5); // Selecciona un LED aleatorio para empezar
digitalWrite(ledPins[currentLed], LOW); // Apaga el LED seleccionado
break;
}
}
} else {
// Durante el juego
if (millis() - startTime < gameTime) { // Si el tiempo de juego no ha terminado
for (int i = 0; i < 5; i++) {
if (digitalRead(buttonPins[currentLed]) == LOW) { // Si se presiona el botón correcto
digitalWrite(ledPins[currentLed], HIGH); // Apaga el LED actual
delay(200); // Pequeña pausa para evitar lecturas dobles
currentLed = random(0, 5); // Selecciona un nuevo LED aleatorio
digitalWrite(ledPins[currentLed], LOW); // Enciende el nuevo LED
break;
}
}
} else {
// Termina el juego, enciende todos los LEDs de nuevo
for (int i = 0; i < 5; i++) {
digitalWrite(ledPins[i], HIGH);
}
while (true); // Detiene el juego
}
}
}