Using Timer Interrupt and Reload Timer
Posted: Thu Jul 18, 2019 3:05 am
Hi all,
I have setup a timer interrupt to trigger every 5 seconds. However if a button is pressed before 5 seconds is up, the timer should restart again.
Is there a way to reload the timer without having to reinitalise the timer all over again? Currently only this works:
I have setup a timer interrupt to trigger every 5 seconds. However if a button is pressed before 5 seconds is up, the timer should restart again.
Is there a way to reload the timer without having to reinitalise the timer all over again? Currently only this works:
Code: Select all
Serial.println("Reload Timer");
timerAlarmDisable(timer); // stop alarm
timerDetachInterrupt(timer); // detach interrupt
timerEnd(timer); // end timer
timer = timerBegin(0, 80, true); // start time again
timerAttachInterrupt(timer, &onTimer, true); // attach interrupt again
timerAlarmWrite(timer, 5000000, true); // start alarm again
timerAlarmEnable(timer); // enable alarm again