#define LED_BUILTIN 25
hw_timer_t *timer = NULL;
volatile bool has_expired = false;
volatile bool led_state = false;
void IRAM_ATTR timerInterrupcion() {
has_expired = true;
}
void setup() {
Serial.begin(9600);
pinMode(LED_BUILTIN, OUTPUT);
timer = timerBegin(0, 80, true); // Timer 0, clock divider 80
timerAttachInterrupt(timer, &timerInterrupcion, true); // Attach the interrupt handling function
timerAlarmWrite(timer, 300000, true); // Interrupt every 1 second
timerAlarmEnable(timer); // Enable the alarm
}
void loop() {
if(has_expired)
{
// Tasks to perform when the Timer interrupt is triggered
led_state = !led_state;
digitalWrite(LED_BUILTIN, led_state);
char info[255];
sprintf(info, "Toggle led! -> %X", led_state);
Serial.println(info);
has_expired = false;
}
}