int leds[16] = {
21, 22, 23, 19, 16, 17, 32, 33,
25, 26, 27, 14, 12, 13, 2, 15
};
// Pines de los pulsadores
int boton1 = 18;
int boton2 = 5;
// Tiempos de velocidad
int tiempos[16] = {
1000, 900, 800, 700,
600, 500, 400, 300,
250, 200, 175, 150,
125, 100, 75, 50
};
// Velocidad inicial
int velocidad = 0;
// CONFIGURACION INICIAL
void setup() {
// Configurar los LED como salidas
for (int i = 0; i < 16; i++) {
pinMode(leds[i], OUTPUT);
digitalWrite(leds[i], LOW);
}
// Configurar los pulsadores
pinMode(boton1, INPUT_PULLUP);
pinMode(boton2, INPUT_PULLUP);
}
// REVISION DE PULSADORES
void revisarBotones() {
// Pulsador 1: aumentar velocidad
if (digitalRead(boton1) == LOW) {
if (velocidad < 15) {
velocidad++;
}
// Esperar a que se suelte el pulsador
while (digitalRead(boton1) == LOW) {
delay(10);
}
delay(35);
}
// Pulsador 2: disminuir velocidad
if (digitalRead(boton2) == LOW) {
if (velocidad > 0) {
velocidad--;
}
// Esperar a que se suelte el pulsador
while (digitalRead(boton2) == LOW) {
delay(10);
}
delay(35);
}
}
// PROGRAMA PRINCIPAL
void loop() {
// MOVIMIENTO DE IZQUIERDA A DERECHA
for (int i = 0; i < 16; i++) {
// Encender LED
digitalWrite(leds[i], HIGH);
int contador = 0;
// Controlar el tiempo y revisar pulsadores
while (contador < tiempos[velocidad]) {
revisarBotones();
delay(10);
contador = contador + 10;
}
// Apagar LED
digitalWrite(leds[i], LOW);
}
// MOVIMIENTO DE DERECHA A IZQUIERDA
for (int i = 14; i >= 0; i--) {
// Encender LED
digitalWrite(leds[i], HIGH);
int contador = 0;
// Controlar el tiempo y revisar pulsadores
while (contador < tiempos[velocidad]) {
revisarBotones();
delay(10);
contador = contador + 10;
}
// Apagar LED
digitalWrite(leds[i], LOW);
}
}
// int leds[16] = {
// 15, 2, 4, 16, 17, 5, 18, 19, 22, 14, 12, 27, 32, 33, 25, 26
// BOTON 1 13
// BOTON 2 23
Loading
esp32-devkit-c-v4
esp32-devkit-c-v4