Alternative to PolledTimeout?

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
  }
}

Not my territory but... Can You describe "the big picture" where/how/for what You will use this? Surely things can be done....

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.

Hello teddyz

Brew your own timer using the millis() function explained in the BlinkWithOutDelay to be found in the IDE.

Have a nice day and enjoy coding in C++.

Thanks, but this is exactly what I want to avoid right now. Nothing I do can be as neat as PolledTimeout that I need to replace.

It does not have to be neat to work properly, which Blink Without Delay does do.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.