// not running on wokwi
//Source: https://docs.espressif.com/projects/arduino-esp32/en/latest/api/timer.html
// in this example the led is blinking every second without the use of the delay function
// by using timer interrupts:
// Advantage: the code is not interrupted by a delay and therefore the entire microcontroller is not blocked
// HTL - Anichstraße - Biomedizin und Gesundheitstechnik v1.0 Dez.24
#define LED 27
//declare timer variable (pointer)
hw_timer_t *timer = NULL;
// Method called by the timer interrupt
void IRAM_ATTR Timer0_ISR()
{
digitalWrite(LED, !digitalRead(LED));
}
void setup() {
pinMode(LED, OUTPUT);
// Set timer frequency to 1Mhz
timer = timerBegin(1000000);
//attach an interrupt to the timer
timerAttachInterrupt(timer, &Timer0_ISR);
// Set alarm to call onTimer function every second (value in microseconds).
// Repeat the alarm (third parameter) with unlimited count = 0 (fourth parameter).
timerAlarm(timer, 1000000, true, 0);
}
void loop()
{
// Do Nothing!
delay(10); // only for wokwi
}