// Pines para relés y botones
const int numRelays = 10;
const int relayPins[numRelays] = {2, 19, 20, 21, 35, 36, 37, 38, 39, 40}; // Pines OUTPUT
const int buttonPins[numRelays] = {4, 5, 6, 7, 8, 9, 10, 11, 12, 13}; // Pines INPUT_PULLUP
bool relayStates[numRelays] = {0};
bool lastButtonStates[numRelays] = {0};
void setup() {
for (int i = 0; i < numRelays; i++) {
pinMode(relayPins[i], OUTPUT);
digitalWrite(relayPins[i], LOW); // Relé apagado al inicio
pinMode(buttonPins[i], INPUT_PULLUP); // Botón activo en LOW
}
}
void loop() {
for (int i = 0; i < numRelays; i++) {
bool currentButton = digitalRead(buttonPins[i]) == LOW;
// Flanco de bajada = botón presionado
if (currentButton && !lastButtonStates[i]) {
relayStates[i] = !relayStates[i]; // Cambia estado del relé
digitalWrite(relayPins[i], relayStates[i] ? HIGH : LOW);
}
lastButtonStates[i] = currentButton;
}
delay(50); // Antirebote básico
}
Producto 1
Producto 2
Producto 3
Producto 4
Producto 5
Producto 6
Producto 7
Producto 8
Producto 9
Producto 10