Converting 2.0.17 Timer code to 3.0+
Posted: Fri Aug 16, 2024 3:16 am
I am attempting to upgrade some code written with the older Timer library for the esp32 2.17.0 Arduino library that looks something like this:
```
askRequestTimer = timerBegin(0, 80, true);
timerAttachInterrupt(askRequestTimer, &onAskReqTimer, true);
timerAlarmWrite(askRequestTimer, 5*1000000, true);//send out an ask every 5 secs
timerAlarmEnable(askRequestTimer);
askExpireTimer = timerBegin(1, 80, true);
timerAttachInterrupt(askExpireTimer, &onAskExpireTimer, true);
timerAlarmWrite(askExpireTimer, expireLength*1000000, true);
timerAlarmEnable(askExpireTimer);
timerStop(askExpireTimer);
```
Give the changes outlined here https://docs.espressif.com/projects/ard ... o_3.0.html, timerBegin and timerAlarm have been updated, so I'm trying to reflect those changes.
This is what I currently have:
```
askRequestTimer = timerBegin(80000000); // 80MHz
timerAttachInterrupt(askRequestTimer, &onAskReqTimer);
timerAlarm(askRequestTimer, 5 * 1000000, true, 0); //send out an ask every 5 secs
askExpireTimer = timerBegin(80000000);
timerAttachInterrupt(askExpireTimer, &onAskExpireTimer);
timerAlarm(askExpireTimer, expireLength * 1000000, true, 0);
timerStop(askExpireTimer);
```
I'm wondering if this is equivalent? Or if someone could provide advice on how to update the code?
Thank you!
```
askRequestTimer = timerBegin(0, 80, true);
timerAttachInterrupt(askRequestTimer, &onAskReqTimer, true);
timerAlarmWrite(askRequestTimer, 5*1000000, true);//send out an ask every 5 secs
timerAlarmEnable(askRequestTimer);
askExpireTimer = timerBegin(1, 80, true);
timerAttachInterrupt(askExpireTimer, &onAskExpireTimer, true);
timerAlarmWrite(askExpireTimer, expireLength*1000000, true);
timerAlarmEnable(askExpireTimer);
timerStop(askExpireTimer);
```
Give the changes outlined here https://docs.espressif.com/projects/ard ... o_3.0.html, timerBegin and timerAlarm have been updated, so I'm trying to reflect those changes.
This is what I currently have:
```
askRequestTimer = timerBegin(80000000); // 80MHz
timerAttachInterrupt(askRequestTimer, &onAskReqTimer);
timerAlarm(askRequestTimer, 5 * 1000000, true, 0); //send out an ask every 5 secs
askExpireTimer = timerBegin(80000000);
timerAttachInterrupt(askExpireTimer, &onAskExpireTimer);
timerAlarm(askExpireTimer, expireLength * 1000000, true, 0);
timerStop(askExpireTimer);
```
I'm wondering if this is equivalent? Or if someone could provide advice on how to update the code?
Thank you!