#define NUM_LEDS 8
#define TOUCH_PIN_1 32 // Pin para el primer sensor táctil
#define TOUCH_PIN_2 33 // Pin para el segundo sensor táctil
// Define los pines para los LEDs
int ledPins[NUM_LEDS] = {2, 4, 5, 12, 13, 14, 15, 16};
// Define los pines para los sensores táctiles
int touchSensorPin1 = TOUCH_PIN_1;
int touchSensorPin2 = TOUCH_PIN_2;
int ledState[NUM_LEDS];
void setup() {
Serial.begin(115200);
// Configura los pines de los sensores táctiles como entrada
pinMode(touchSensorPin1, INPUT);
pinMode(touchSensorPin2, INPUT);
// Configura los pines de los LEDs como salida
for (int i = 0; i < NUM_LEDS; i++) {
pinMode(ledPins[i], OUTPUT);
ledState[i] = LOW;
}
}
void loop() {
// Verificar el estado del primer sensor táctil
if (digitalRead(touchSensorPin1) == HIGH) {
incrementarLeds();
delay(500); // Espera para evitar múltiples incrementos con un solo toque
}
// Verificar el estado del segundo sensor táctil
if (digitalRead(touchSensorPin2) == HIGH) {
decrementarLeds();
delay(500); // Espera para evitar múltiples decrementos con un solo toque
}
}
void incrementarLeds() {
for (int i = 0; i < NUM_LEDS; i++) {
if (ledState[i] == LOW) {
ledState[i] = HIGH;
digitalWrite(ledPins[i], HIGH);
break; // Incrementar solo un LED a la vez
}
}
}
void decrementarLeds() {
for (int i = NUM_LEDS - 1; i >= 0; i--) {
if (ledState[i] == HIGH) {
ledState[i] = LOW;
digitalWrite(ledPins[i], LOW);
break; // Decrementar solo un LED a la vez
}
}
}