For ESP8266 I used PolledTimeout to do stuff where the timing is not critical. It consumed no timers, so no limitation on how many of these I could have.
Great, but this function is not available on ESP32. Do you know of a good replacement?
Example:
#include <PolledTimeout.h> // https://github.com/esp8266/Arduino/blob/master/cores/esp8266/PolledTimeout.h
void loop() {
static esp8266::polledTimeout::periodicFastMs periodic_1s( 1000 ); // "Fast" versions sacrifices time range for improved precision and reduced execution time (by 86%)
static esp8266::polledTimeout::periodicFastMs periodic_5s( 5000 ); // max is 26843 ms (26.8 s)
static esp8266::polledTimeout::periodicMs periodic_60s( 60000 );
static esp8266::polledTimeout::periodicMs periodic_300s( 300000 );
// do every 1 seconds
if ( periodic_1s ) {
// do some stuff here
}
}
In my IoT-thingies I use them as timers, examples:
Every 1s - check if something shall be sent on mqtt
Every 5s - update some topics on mqtt, update content on display
Every 300s - save data to eeprom (if needed, not on every change to save flash lifetime)
In the example above, the periodic_1s is trigged once per second. No need to reset something, which makes code simple.