#define SERIAL_SPEED 9600
const int buttonPin = 12;
const int ledPin = 25;
int ledState;
volatile bool led_change;
unsigned long last_DebounceTime = 0;
unsigned long debounce_delay = 70; // Probar con varios valores
// hasta que funcione (10, 20,...)
void IRAM_ATTR button_ISR() {
if(millis() - last_DebounceTime > debounce_delay){
// Software debouncing buton
// ets_printf("ISR triggered\n");
led_change = true;
}
last_DebounceTime = millis();
}
void setup() {
// Configuracion de puertos
pinMode(ledPin, OUTPUT);
Serial.begin(SERIAL_SPEED);
// Inicializacion de variables
led_change = false;
ledState = LOW;
digitalWrite(ledPin, ledState);
attachInterrupt(digitalPinToInterrupt(buttonPin), button_ISR, RISING);
// Iniciacion del puerto serial
Serial.println("Inicio...");
}
void loop() {
if (led_change == true) {
// Transición positiva
Serial.print("[T+]-> Led:");
Serial.println(ledState);
ledState = !ledState;
digitalWrite(ledPin, ledState);
led_change = false;
}
}