// Definición de pines para los LEDs
const int leds[] = {2, 3, 4, 5, 6, 7, 8, 9};
// Definición de pines para los pulsadores
const int boton1 = 10;
const int boton2 = 11;
const int boton3 = 12;
void setup() {
// Configurar pines de los LEDs como salida
for (int i = 0; i < 8; i++) {
pinMode(leds[i], OUTPUT);
}
// Configurar pines de los pulsadores como entrada
pinMode(boton1, INPUT_PULLUP);
pinMode(boton2, INPUT_PULLUP);
pinMode(boton3, INPUT_PULLUP);
}
void loop() {
// Leer el estado de los pulsadores
int estadoBoton1 = digitalRead(boton1);
int estadoBoton2 = digitalRead(boton2);
int estadoBoton3 = digitalRead(boton3);
// Si se presiona el tercer pulsador, detener todas las secuencias
if (estadoBoton3 == LOW) {
apagarLeds();
} else if (estadoBoton1 == LOW) {
secuencia1();
} else if (estadoBoton2 == LOW) {
secuencia2();
}
}
void secuencia1() {
// Encender LEDs de afuera hacia el centro
for (int i = 0; i < 4; i++) {
if (digitalRead(boton3) == LOW) return;
digitalWrite(leds[i], HIGH);
digitalWrite(leds[7 - i], HIGH);
delay(200);
}
// Apagar LEDs del centro hacia afuera
for (int i = 3; i >= 0; i--) {
if (digitalRead(boton3) == LOW) return;
digitalWrite(leds[i], LOW);
digitalWrite(leds[7 - i], LOW);
delay(200);
}
}
void secuencia2() {
// Encender LEDs pares
for (int i = 0; i < 8; i += 2) {
if (digitalRead(boton3) == LOW) return;
digitalWrite(leds[i], HIGH);
delay(200);
}
// Apagar LEDs pares
for (int i = 0; i < 8; i += 2) {
if (digitalRead(boton3) == LOW) return;
digitalWrite(leds[i], LOW);
delay(200);
}
// Encender LEDs impares
for (int i = 1; i < 8; i += 2) {
if (digitalRead(boton3) == LOW) return;
digitalWrite(leds[i], HIGH);
delay(200);
}
// Apagar LEDs impares
for (int i = 1; i < 8; i += 2) {
if (digitalRead(boton3) == LOW) return;
digitalWrite(leds[i], LOW);
delay(200);
}
}
void apagarLeds() {
for (int i = 0; i < 8; i++) {
digitalWrite(leds[i], LOW);
}
}