#define PULS_PIN 34
#define LED_PIN 23
hw_timer_t * TT = NULL; // estructura de datos del timer
const unsigned long frecuencias[] = {200, 400, 500, 1000}; // frecuencias
volatile int id_freq = 0; // indice 0 a 3
void IRAM_ATTR ISR_pulsador() {
static unsigned long ultimo_tiempo_interrupcion = 0;
unsigned long tiempo_actual = millis();
if (tiempo_actual - ultimo_tiempo_interrupcion > 200) {
ultimo_tiempo_interrupcion = tiempo_actual;
id_freq = (id_freq + 1) % 4;
timerWrite(TT,0);
timerAlarm(TT, frecuencias[id_freq]*1e3, true, 0);
}
}
volatile int tiempo;
void IRAM_ATTR ISR_timer() {
static bool estado_led = false;
estado_led = !estado_led;
digitalWrite(LED_PIN, estado_led);
}
void setup() {
Serial.begin(115200);
pinMode(LED_PIN, OUTPUT);
digitalWrite(LED_PIN, LOW); //apagado
// Interrupción en flanco descendente
attachInterrupt(digitalPinToInterrupt(PULS_PIN), ISR_pulsador, RISING);
TT = timerBegin(1e6); // cuenta useg
timerAttachInterrupt(TT, &ISR_timer);
timerAlarm(TT, frecuencias[0]*1e3, true, 0); // alarma cada 3 segundos - se repite indefinidamente
}
void loop() {
delay(10);
}