const int ledPins[] = {2, 3, 4, 5, 6, 7, 8, 9}; // Pines de los LEDs
const int buttonPins[] = {10, 11, 12}; // Pines de los pulsadores
const int potPin = A0; // Pin del potenciómetro
int currentState = 0; // Estado actual de la secuencia
int currentLed = 0; // LED actual que se enciende
bool isRunning = true; // Bandera para detener la secuencia
int speed = 50; // Velocidad inicial
void setup() {
for (int i = 0; i < 8; i++) {
pinMode(ledPins[i], OUTPUT);
}
for (int i = 0; i < 3; i++) {
pinMode(buttonPins[i], INPUT);
}
pinMode(potPin, INPUT);
}
void loop() {
// Leer los pulsadores
int buttonState1 = digitalRead(buttonPins[0]);
int buttonState2 = digitalRead(buttonPins[1]);
int buttonState3 = digitalRead(buttonPins[2]);
// Leer el potenciómetro
int potValue = analogRead(potPin);
speed = map(potValue, 0, 1023, 10, 100);
// Funcionalidad 1: Prender LEDs de afuera hacia adentro y viceversa
if (buttonState1 == HIGH && isRunning) {
currentState = (currentState + 1) % 2;
if (currentState == 0) {
for (int i = 0; i < 4; i++) {
digitalWrite(ledPins[i], LOW);
digitalWrite(ledPins[7 - i], LOW);
}
currentLed = 0;
} else {
for (int i = 0; i < 4; i++) {
digitalWrite(ledPins[i], HIGH);
digitalWrite(ledPins[7 - i], HIGH);
}
currentLed = 3;
}
}
// Funcionalidad 1: Actualizar la secuencia
if (isRunning && currentState == 0) {
digitalWrite(ledPins[currentLed], HIGH);
delay(speed);
digitalWrite(ledPins[currentLed], LOW);
currentLed = (currentLed + 1) % 4;
if (currentLed == 4) {
currentLed = 3;
}
} else if (isRunning && currentState == 1) {
digitalWrite(ledPins[currentLed], HIGH);
delay(speed);
digitalWrite(ledPins[currentLed], LOW);
currentLed = (currentLed - 1) % 4;
if (currentLed < 0) {
currentLed = 3;
}
}
// Funcionalidad 2: Prender LEDs de manera par e impar
if (buttonState2 == HIGH && isRunning) {
currentState = (currentState + 1) % 2;
if (currentState == 0) {
for (int i = 0; i < 8; i++) {
if (i % 2 == 0) {
digitalWrite(ledPins[i], HIGH);
} else {
digitalWrite(ledPins[i], LOW);
}
}
} else {
for (int i = 0; i < 8; i++) {
if (i % 2 != 0) {
digitalWrite(ledPins[i], HIGH);
} else {
digitalWrite(ledPins[i], LOW);
}
}
}
}
// Funcionalidad 3: Detener la secuencia y apagar LEDs
if (buttonState3 == HIGH) {
isRunning = false;
for (int i = 0; i < 8; i++) {
digitalWrite(ledPins[i], LOW);
}
}
}