Git Product home page Git Product logo

ticker's People

Contributors

combs avatar miguelestevez avatar per1234 avatar schwerthecht avatar sstaub avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ticker's Issues

Update repeat type to 32 bit

Hi,

I'm using this library to fade in/out lights. So i'm having a very short timer (1ms) and a very large repeat value. Just for 1 second, that is already 1000. And with some experiments with a light that acts as a wakeup light (so slowly turn on over 30 minutes or so) means it has a value of: 1800000. Well above the 16 bit capacity.

Therefore i'm hoping the 16 bit restriction can be upped to 32 bit. I tried it locally, it works just fine!

Cheers,
Mark

conflict

then explain how not to have a confluence with the internal ESP libraries.
when I declare #include "Ticker.h" it's not yours to use.

Several libraries found for "Ticker.h"
Used: C: \ Users \ stephane \ AppData \ Local \ Arduino15 \ packages \ esp8266 \ hardware \ esp8266 \ 2.7.4 \ libraries \ Ticker
Not used: C: \ Users \ stephane \ Documents \ Arduino \ libraries \ Ticker-master

how to do ?

Does not work

Hi, I was happy to find a Ticker libary but it does not work.
I'm using

  • Arduino 1.8.5
  • NodeMCU 1.0 (ESP-12E)
  • Windows
    Ticker Lib is installed and found by Arduino
    I loaded the Ticker example and got the compiler errors:

Arduino: 1.8.5 (Windows 10), Board: "NodeMCU 1.0 (ESP-12E Module), 80 MHz, Flash, Legacy (new can return nullptr), All SSL ciphers (most compatible), 4MB (FS:2MB OTA:~1019KB), 2, v2 Lower Memory, Disabled, None, Only Sketch, 115200"

C:\Program Files (x86)\Arduino\arduino-builder -dump-prefs -logger=machine -hardware C:\Program Files (x86)\Arduino\hardware -hardware C:\Users\aremp\AppData\Local\Arduino15\packages -tools C:\Program Files (x86)\Arduino\tools-builder -tools C:\Program Files (x86)\Arduino\hardware\tools\avr -tools C:\Users\aremp\AppData\Local\Arduino15\packages -built-in-libraries C:\Program Files (x86)\Arduino\libraries -libraries C:\Users\aremp\OneDrive\Dokumente\Arduino\libraries -fqbn=esp8266:esp8266:nodemcuv2:xtal=80,vt=flash,exception=legacy,ssl=all,eesz=4M2M,led=2,ip=lm2f,dbg=Disabled,lvl=None____,wipe=none,baud=115200 -ide-version=10805 -build-path C:\Users\aremp\AppData\Local\Temp\arduino_build_297300 -warnings=none -build-cache C:\Users\aremp\AppData\Local\Temp\arduino_cache_493861 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.mklittlefs.path=C:\Users\aremp\AppData\Local\Arduino15\packages\esp8266\tools\mklittlefs\2.5.0-4-69bd9e6 -prefs=runtime.tools.mkspiffs.path=C:\Users\aremp\AppData\Local\Arduino15\packages\esp8266\tools\mkspiffs\2.5.0-4-b40a506 -prefs=runtime.tools.python3.path=C:\Users\aremp\AppData\Local\Arduino15\packages\esp8266\tools\python3\3.7.2-post1 -prefs=runtime.tools.xtensa-lx106-elf-gcc.path=C:\Users\aremp\AppData\Local\Arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\2.5.0-4-b40a506 -verbose C:\Users\aremp\Documents\Arduino\libraries\Ticker\examples\Ticker\Ticker.ino
C:\Program Files (x86)\Arduino\arduino-builder -compile -logger=machine -hardware C:\Program Files (x86)\Arduino\hardware -hardware C:\Users\aremp\AppData\Local\Arduino15\packages -tools C:\Program Files (x86)\Arduino\tools-builder -tools C:\Program Files (x86)\Arduino\hardware\tools\avr -tools C:\Users\aremp\AppData\Local\Arduino15\packages -built-in-libraries C:\Program Files (x86)\Arduino\libraries -libraries C:\Users\aremp\OneDrive\Dokumente\Arduino\libraries -fqbn=esp8266:esp8266:nodemcuv2:xtal=80,vt=flash,exception=legacy,ssl=all,eesz=4M2M,led=2,ip=lm2f,dbg=Disabled,lvl=None____,wipe=none,baud=115200 -ide-version=10805 -build-path C:\Users\aremp\AppData\Local\Temp\arduino_build_297300 -warnings=none -build-cache C:\Users\aremp\AppData\Local\Temp\arduino_cache_493861 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.mklittlefs.path=C:\Users\aremp\AppData\Local\Arduino15\packages\esp8266\tools\mklittlefs\2.5.0-4-69bd9e6 -prefs=runtime.tools.mkspiffs.path=C:\Users\aremp\AppData\Local\Arduino15\packages\esp8266\tools\mkspiffs\2.5.0-4-b40a506 -prefs=runtime.tools.python3.path=C:\Users\aremp\AppData\Local\Arduino15\packages\esp8266\tools\python3\3.7.2-post1 -prefs=runtime.tools.xtensa-lx106-elf-gcc.path=C:\Users\aremp\AppData\Local\Arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\2.5.0-4-b40a506 -verbose C:\Users\aremp\Documents\Arduino\libraries\Ticker\examples\Ticker\Ticker.ino
Using board 'nodemcuv2' from platform in folder: C:\Users\aremp\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.3
Using core 'esp8266' from platform in folder: C:\Users\aremp\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.3
Detecting libraries used...
"C:\Users\aremp\AppData\Local\Arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\2.5.0-4-b40a506/bin/xtensa-lx106-elf-g++" -D__ets__ -DICACHE_FLASH -U__STRICT_ANSI__ "-IC:\Users\aremp\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.3/tools/sdk/include" "-IC:\Users\aremp\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.3/tools/sdk/lwip2/include" "-IC:\Users\aremp\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.3/tools/sdk/libc/xtensa-lx106-elf/include" "-IC:\Users\aremp\AppData\Local\Temp\arduino_build_297300/core" -c -w -Os -g -mlongcalls -mtext-section-literals -fno-rtti -falign-functions=4 -std=gnu++11 -ffunction-sections -fdata-sections -fno-exceptions -w -x c++ -E -CC -DNONOSDK22x_190703=1 -DF_CPU=80000000L -DLWIP_OPEN_SRC -DTCP_MSS=536 -DLWIP_FEATURES=1 -DLWIP_IPV6=0 -DARDUINO=10805 -DARDUINO_ESP8266_NODEMCU -DARDUINO_ARCH_ESP8266 -DARDUINO_BOARD="ESP8266_NODEMCU" -DLED_BUILTIN=2 -DFLASHMODE_DIO -DESP8266 "-IC:\Users\aremp\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.3\cores\esp8266" "-IC:\Users\aremp\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.3\variants\nodemcu" "C:\Users\aremp\AppData\Local\Temp\arduino_build_297300\sketch\Ticker.ino.cpp" -o "nul"
"C:\Users\aremp\AppData\Local\Arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\2.5.0-4-b40a506/bin/xtensa-lx106-elf-g++" -D__ets__ -DICACHE_FLASH -U__STRICT_ANSI__ "-IC:\Users\aremp\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.3/tools/sdk/include" "-IC:\Users\aremp\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.3/tools/sdk/lwip2/include" "-IC:\Users\aremp\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.3/tools/sdk/libc/xtensa-lx106-elf/include" "-IC:\Users\aremp\AppData\Local\Temp\arduino_build_297300/core" -c -w -Os -g -mlongcalls -mtext-section-literals -fno-rtti -falign-functions=4 -std=gnu++11 -ffunction-sections -fdata-sections -fno-exceptions -w -x c++ -E -CC -DNONOSDK22x_190703=1 -DF_CPU=80000000L -DLWIP_OPEN_SRC -DTCP_MSS=536 -DLWIP_FEATURES=1 -DLWIP_IPV6=0 -DARDUINO=10805 -DARDUINO_ESP8266_NODEMCU -DARDUINO_ARCH_ESP8266 -DARDUINO_BOARD="ESP8266_NODEMCU" -DLED_BUILTIN=2 -DFLASHMODE_DIO -DESP8266 "-IC:\Users\aremp\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.3\cores\esp8266" "-IC:\Users\aremp\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.3\variants\nodemcu" "-IC:\Program Files (x86)\Arduino\libraries\Ticker" "C:\Users\aremp\AppData\Local\Temp\arduino_build_297300\sketch\Ticker.ino.cpp" -o "nul"
"C:\Users\aremp\AppData\Local\Arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\2.5.0-4-b40a506/bin/xtensa-lx106-elf-g++" -D__ets__ -DICACHE_FLASH -U__STRICT_ANSI__ "-IC:\Users\aremp\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.3/tools/sdk/include" "-IC:\Users\aremp\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.3/tools/sdk/lwip2/include" "-IC:\Users\aremp\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.3/tools/sdk/libc/xtensa-lx106-elf/include" "-IC:\Users\aremp\AppData\Local\Temp\arduino_build_297300/core" -c -w -Os -g -mlongcalls -mtext-section-literals -fno-rtti -falign-functions=4 -std=gnu++11 -ffunction-sections -fdata-sections -fno-exceptions -w -x c++ -E -CC -DNONOSDK22x_190703=1 -DF_CPU=80000000L -DLWIP_OPEN_SRC -DTCP_MSS=536 -DLWIP_FEATURES=1 -DLWIP_IPV6=0 -DARDUINO=10805 -DARDUINO_ESP8266_NODEMCU -DARDUINO_ARCH_ESP8266 -DARDUINO_BOARD="ESP8266_NODEMCU" -DLED_BUILTIN=2 -DFLASHMODE_DIO -DESP8266 "-IC:\Users\aremp\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.3\cores\esp8266" "-IC:\Users\aremp\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.3\variants\nodemcu" "-IC:\Program Files (x86)\Arduino\libraries\Ticker" "C:\Program Files (x86)\Arduino\libraries\Ticker\Ticker.cpp" -o "nul"
Generating function prototypes...
"C:\Users\aremp\AppData\Local\Arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\2.5.0-4-b40a506/bin/xtensa-lx106-elf-g++" -D__ets__ -DICACHE_FLASH -U__STRICT_ANSI__ "-IC:\Users\aremp\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.3/tools/sdk/include" "-IC:\Users\aremp\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.3/tools/sdk/lwip2/include" "-IC:\Users\aremp\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.3/tools/sdk/libc/xtensa-lx106-elf/include" "-IC:\Users\aremp\AppData\Local\Temp\arduino_build_297300/core" -c -w -Os -g -mlongcalls -mtext-section-literals -fno-rtti -falign-functions=4 -std=gnu++11 -ffunction-sections -fdata-sections -fno-exceptions -w -x c++ -E -CC -DNONOSDK22x_190703=1 -DF_CPU=80000000L -DLWIP_OPEN_SRC -DTCP_MSS=536 -DLWIP_FEATURES=1 -DLWIP_IPV6=0 -DARDUINO=10805 -DARDUINO_ESP8266_NODEMCU -DARDUINO_ARCH_ESP8266 -DARDUINO_BOARD="ESP8266_NODEMCU" -DLED_BUILTIN=2 -DFLASHMODE_DIO -DESP8266 "-IC:\Users\aremp\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.3\cores\esp8266" "-IC:\Users\aremp\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.3\variants\nodemcu" "-IC:\Program Files (x86)\Arduino\libraries\Ticker" "C:\Users\aremp\AppData\Local\Temp\arduino_build_297300\sketch\Ticker.ino.cpp" -o "C:\Users\aremp\AppData\Local\Temp\arduino_build_297300\preproc\ctags_target_for_gcc_minus_e.cpp"
"C:\Program Files (x86)\Arduino\tools-builder\ctags\5.8-arduino11/ctags" -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives "C:\Users\aremp\AppData\Local\Temp\arduino_build_297300\preproc\ctags_target_for_gcc_minus_e.cpp"
Sketch wird kompiliert...
"C:\Users\aremp\AppData\Local\Arduino15\packages\esp8266\tools\python3\3.7.2-post1/python3" "C:\Users\aremp\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.3/tools/signing.py" --mode header --publickey "C:\Users\aremp\Documents\Arduino\libraries\Ticker\examples\Ticker/public.key" --out "C:\Users\aremp\AppData\Local\Temp\arduino_build_297300/core/Updater_Signing.h"
"C:\Users\aremp\AppData\Local\Arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\2.5.0-4-b40a506/bin/xtensa-lx106-elf-g++" -D__ets__ -DICACHE_FLASH -U__STRICT_ANSI__ "-IC:\Users\aremp\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.3/tools/sdk/include" "-IC:\Users\aremp\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.3/tools/sdk/lwip2/include" "-IC:\Users\aremp\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.3/tools/sdk/libc/xtensa-lx106-elf/include" "-IC:\Users\aremp\AppData\Local\Temp\arduino_build_297300/core" -c -w -Os -g -mlongcalls -mtext-section-literals -fno-rtti -falign-functions=4 -std=gnu++11 -MMD -ffunction-sections -fdata-sections -fno-exceptions -DNONOSDK22x_190703=1 -DF_CPU=80000000L -DLWIP_OPEN_SRC -DTCP_MSS=536 -DLWIP_FEATURES=1 -DLWIP_IPV6=0 -DARDUINO=10805 -DARDUINO_ESP8266_NODEMCU -DARDUINO_ARCH_ESP8266 -DARDUINO_BOARD="ESP8266_NODEMCU" -DLED_BUILTIN=2 -DFLASHMODE_DIO -DESP8266 "-IC:\Users\aremp\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.3\cores\esp8266" "-IC:\Users\aremp\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.3\variants\nodemcu" "-IC:\Program Files (x86)\Arduino\libraries\Ticker" "C:\Users\aremp\AppData\Local\Temp\arduino_build_297300\sketch\Ticker.ino.cpp" -o "C:\Users\aremp\AppData\Local\Temp\arduino_build_297300\sketch\Ticker.ino.cpp.o"
Ticker:13: error: 'MILLIS' was not declared in this scope

Ticker timer1(printMessage, 0, 1, MILLIS);

                               ^

Ticker:14: error: 'MILLIS' was not declared in this scope

Ticker timer2(printCounter, 1000, MILLIS);

                               ^

Ticker:15: error: 'MILLIS' was not declared in this scope

Ticker timer3(printCountdown, 1000, 5, MILLIS);

                                    ^

Ticker:16: error: no matching function for call to 'Ticker::Ticker(void (&)(), int)'

Ticker timer4(blink, 500);

                     ^

C:\Users\aremp\Documents\Arduino\libraries\Ticker\examples\Ticker\Ticker.ino:16:25: note: candidates are:

In file included from C:\Users\aremp\Documents\Arduino\libraries\Ticker\examples\Ticker\Ticker.ino:1:0:

C:\Program Files (x86)\Arduino\libraries\Ticker/Ticker.h:32:2: note: Ticker::Ticker()

Ticker();

^

C:\Program Files (x86)\Arduino\libraries\Ticker/Ticker.h:32:2: note: candidate expects 0 arguments, 2 provided

C:\Program Files (x86)\Arduino\libraries\Ticker/Ticker.h:29:7: note: Ticker::Ticker(const Ticker&)

class Ticker

   ^

C:\Program Files (x86)\Arduino\libraries\Ticker/Ticker.h:29:7: note: candidate expects 1 argument, 2 provided

Ticker:17: error: 'MICROS_MICROS' was not declared in this scope

Ticker timer5(printCountUS, 100, 0, MICROS_MICROS);

                                 ^

C:\Users\aremp\Documents\Arduino\libraries\Ticker\examples\Ticker\Ticker.ino: In function 'void setup()':

Ticker:24: error: 'class Ticker' has no member named 'start'

timer1.start();

      ^

Ticker:25: error: 'class Ticker' has no member named 'start'

timer2.start();

      ^

Ticker:26: error: 'class Ticker' has no member named 'start'

timer3.start();

      ^

Ticker:27: error: 'class Ticker' has no member named 'start'

timer4.start();

      ^

Ticker:28: error: 'class Ticker' has no member named 'start'

timer5.start();

      ^

C:\Users\aremp\Documents\Arduino\libraries\Ticker\examples\Ticker\Ticker.ino: In function 'void loop()':

Ticker:32: error: 'class Ticker' has no member named 'update'

timer1.update();

      ^

Ticker:33: error: 'class Ticker' has no member named 'update'

timer2.update();

      ^

Ticker:34: error: 'class Ticker' has no member named 'update'

timer3.update();

      ^

Ticker:35: error: 'class Ticker' has no member named 'update'

timer4.update();

      ^

Ticker:36: error: 'class Ticker' has no member named 'update'

timer5.update();

      ^

Ticker:37: error: 'class Ticker' has no member named 'counter'

if (timer4.counter() == 20) timer4.interval(200);

          ^

Ticker:37: error: 'class Ticker' has no member named 'interval'

if (timer4.counter() == 20) timer4.interval(200);

                                  ^

Ticker:38: error: 'class Ticker' has no member named 'counter'

if (timer4.counter() == 80) timer4.interval(1000);

          ^

Ticker:38: error: 'class Ticker' has no member named 'interval'

if (timer4.counter() == 80) timer4.interval(1000);

                                  ^

C:\Users\aremp\Documents\Arduino\libraries\Ticker\examples\Ticker\Ticker.ino: In function 'void printCounter()':

Ticker:43: error: 'class Ticker' has no member named 'counter'

Serial.println(timer2.counter());

                     ^

C:\Users\aremp\Documents\Arduino\libraries\Ticker\examples\Ticker\Ticker.ino: In function 'void printCountdown()':

Ticker:48: error: 'class Ticker' has no member named 'counter'

Serial.println(5 - timer3.counter());

                         ^

Bibliothek Ticker in Version 1.0 im Ordner: C:\Program Files (x86)\Arduino\libraries\Ticker wird verwendet
exit status 1
'MILLIS' was not declared in this scope

Improvements request

Hi,
First of all, nice lib. Helps me a lot.

  • It would be nice if you can add a function to return the interval that is used for ticker. It seems to be not a very big thing but helps me a lot. In a more complex architecture with multiple ticker instance I will not have to keep my self the last interval for each ticker for the case where I need to return information about one of the tickers;
    the function that I need can look like :
uint32_t Ticker::getInterval() {
    if (resolution == MICROS) {
        return this->timer / 1000;
   } else {
        return this->timer;
   }
}
  • Another optimization will be to define the enums by specify the storage as :uint8_t, will earn about 3 bytes for each element in enum, for this library will earn about 21bytes :) :
enum resolution_t:uint8_t {MICROS, MILLIS, MICROS_MICROS};
enum status_t:uint8_t {STOPPED, RUNNING, PAUSED};
  • Other thing will be, but maybe you already thought on this, to go in a direction to create a list of tickers. I think most of the developers are not using this lib for just one ticker but for multiple ones. Maybe worth to manage a list of tickers and the developers to register a ticker

Maybe you are to busy for this changes, if you want I can branch this and do the changes but I don't like to keep projects on which I'm not the owner; plus that I want to be up to date with your changes in this lib. So, if I'm doing the changes can you merge them?

Would a 'Ticker::remaining_count()' function be viable?

Hi, Thank you so much for this library

I tried to make an Inverted Counter with Ticker to find out how many repetitions are left, but I didn't find a specific function.

I saw that there is the function Ticker::remaining(), to return the remaining time to the next tick in ms or us depending on mode.

Would it be feasible to implement a Ticker::remaining_count() function to returns the remaining count?

I believe this function would be useful to countdown to apply in other functions or in Serial.Print, display/LCD...

Something like:
Current tick: Ticker::counter()
Remaining tick: Ticker::remaining_count()

I tried to do it like this (sorry,I'm a beginner in Arduino and ESP):

Ticker displayLCD_countdown_TICKER(displayLCD_countdown, 1000, 60, MILLIS);

displayLCD_countdown(){

int countdown = 60 - displayLCD_countdown_TICKER.counter();

Serial.print(countdown);
Serial.println(" attempt left");

}

But it's not a good solution. If the number 60 is changed in just one place, an error may occur.

error in readme.md

examples

Tickers timer(blink, 1000); // calls function blink() every second, internal resolution is micros, running endless
Tickers timer(blink, 1000, 5); // calls function blink() every second, internal resolution is micros, only 5 repeats

micro ? sure ?

Tickers timer(blink, 1000, 0, MILLIS); // calls function blink() every second, internal resolution is millis, running endless
Tickers timer(blink, 1000, 0, MICROS_MICROS); // calls function blink() every 1000 microsecond, internal resolution is micros, running endless

Cannot load Ticker.h library (conflicts with the default Ticker.h library)

Hi, I am using Arduino IDE 1.8.15 and that has a default library called Ticker.h. I installed your library, but if I try to use it, Arduino IDE refers to the default Ticker.h library and not yours. So it says error such as "error: 'class Ticker' has no member named 'start'", "error: 'class Ticker' has no member named 'update'", "'class Ticker' has no member named 'remaining'". Is there any solution for this issue? Thank you.

[Feature] Allow NULL callbacks and set state to STOPPED

Please consider the following:

Set status = STOPPED; in the constructor. (otherwise it's used uninitialised.)

Allow NULL function pointers. This allows the timer to run, and be polled instead of calling the callback.

Remove all checks on callback:

// if (callback == NULL) return;

Change update to the following:

void Ticker::update() {
if (tick()) {
	if( callback ) callback();
}

Change both instances of:

if (repeat - counts == 1) {
	enabled = false;
}

to be as follows:

if ((repeat - counts) == 1) {
	enabled = false;
	status = STOPPED;
}

With the above changes implemented, a "blocking" delay(ms) routine can easily be coded without having to provide a dummy callback:

void DelayBlocked( uint32_t ms )
{
    Ticker t( NULL, ms, 1, MILLIS );
    t.start();
    do
    {
      t.update();
    } while( STOPPED != t.state() );
}

Without my suggested changes, a "blocking" delay(ms) routine looks like this:

void DelayBlocked( uint32_t ms )
{
    Ticker t( DummyCallback, ms, 1, MILLIS );
    t.start();
    do
    {
      t.update();
    } while( 1 != t.counter() );
}

void DummyCallback()
{
}

Ticker remaining() error.

At least in version 4.2.0.
For MILLIS initiaslisation there is an error within the function remaining().

ticker_midnight=new Ticker(__midnight, mid_start * 1000L, 1, MILLIS); 

The function remaining() is a substraction of the initialised value timer and
the result fo function elapsed().
The value timer has ofcourse already the value in MILLIS (as initialised)
and also the function elapsed() is in the right value by function millis().

uint32_t Ticker::elapsed() {
if (resolution == MILLIS) return millis() - lastTime;
else return micros() - lastTime;
}

So the divide by 1000 in function remaining() is not needed and gives now
wrong values when used as it is now:

return timer / 1000 - elapsed();

Please adapt considder to adapt the function remaining() to:

uint32_t Ticker::remaining() {
return timer - elapsed();
}

Test example:
#include <Ticker.h>

Ticker *ticker_minute;

void __minute(void)
{
Serial.println("__minute(): The end.");
}

void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
while (!Serial);

ticker_minute=new Ticker(__minute, 60 * 1000L, 1, MILLIS);

}

void loop() {
// put your main code here, to run repeatedly:

ticker_minute-> update();
Serial.print("remaining: ");
Serial.println(ticker_minute->remaining());
Serial.print("elapsed: ");
Serial.println(ticker_minute->elapsed());
}

givves as output:

13:25:53.924 -> remaining: 4294929916
13:25:53.924 -> elapsed: 97382
13:25:53.924 -> remaining: 4294929913
13:25:53.924 -> elapsed: 97385
13:25:53.924 -> remaining: 4294929909
13:25:53.924 -> elapsed: 97389
13:25:53.924 -> remaining: 4294929906
13:25:53.924 -> elapsed: 97392
13:25:53.924 -> remaining: 4294929902
13:25:53.924 -> elapsed: 97395
13:25:53.924 -> remaining: 4294929899At least in version 4.2.0.
For MILLIS initiaslisation there is an error within the function remaining().

ticker_midnight=new Ticker(__midnight, mid_start * 1000L, 1, MILLIS); 

The function remaining() is a substraction of the initialised value timer and
the result fo function elapsed().
The value timer has ofcourse already the value in MILLIS (as initialised)
and also the function elapsed() is in the right value by function millis().

uint32_t Ticker::elapsed() {
if (resolution == MILLIS) return millis() - lastTime;
else return micros() - lastTime;
}

So the divide by 1000 in function remaining() is not needed and gives now
wrong values when used as it is now:

return timer / 1000 - elapsed();

Please adapt considder to adapt the function remaining() to:

uint32_t Ticker::remaining() {
return timer - elapsed();
}

Test example:
#include <Ticker.h>

Ticker *ticker_minute;

void __minute(void)
{
Serial.println("__minute(): The end.");
}

void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
while (!Serial);

ticker_minute=new Ticker(__minute, 60 * 1000L, 1, MILLIS);
ticker_minute->start();
}

void loop() {
// put your main code here, to run repeatedly:
static int e=0, el;

el=ticker_minute->elapsed();
if(e!=el/1000)
{
e=el/1000;

ticker_minute-> update();
Serial.print("remaining: ");
Serial.println(ticker_minute->remaining());
Serial.print("elapsed: ");
Serial.println(el);
}

}

gives as output:
15:48:49.419 -> elapsed: 55000
15:48:50.444 -> remaining: 4294911356
15:48:50.444 -> elapsed: 56000
15:48:51.436 -> remaining: 4294910356
15:48:51.436 -> elapsed: 57000
15:48:52.428 -> remaining: 4294909356
15:48:52.428 -> elapsed: 58000
15:48:53.420 -> remaining: 4294908356
15:48:53.420 -> elapsed: 59000
15:48:54.445 -> __minute(): The end.

expected output:
15:38:29.168 -> remaining: 3000
15:38:29.168 -> elapsed: 57000
15:38:30.160 -> remaining: 2000
15:38:30.160 -> elapsed: 58000
15:38:31.153 -> remaining: 1000
15:38:31.153 -> elapsed: 59000
15:38:32.178 -> __minute(): The end.

Thanks

Ed Faber
Netherlands.
13:25:53.924 -> elapsed: 97399
13:25:53.924 -> remaining: 4294929896
13:25:53.924 -> elapsed: 97402
13:25:53.924 -> remaining: 4294929892
13:25:53.924 -> elapsed: 97405
13:25:53.924 -> remaining: 4294929889
13:25:53.924 -> elapsed: 97409

Thanks

Ed Faber
Netherlands.

Versions 4.x.x error compiling for Arduino Due

Hi,
after updating from 3.2.0 to current version my sketch failed compiling.
I am using Arduino IDE 1.8.19 and Arduino SAM Boards package 1.6.12.
The errormessages are complaining about macro swap being called with too less arguments.

But even the examples coming with the library are not compiling either.

how to call a function with arguments

Hello there,
can you please share a way we can call a function and pass it a parameter?
i tried the lambda but i'm getting error..
Ticker smyFunc([](char i) { funcToCall(i); }, 1, 1);

thank you,
Jay

Interval

Could you set the timing interval in microseconds? I mean:
flipper.attach_ms(0.25, flip);

Build failure with STM32 Blue Pill board

When I try to build with version 4.4.0 for a STM32F103C8 Blue Pill board I get the error:

Compiling .pio/build/bluepill_f103c8/lib6e0/Ticker/Ticker.cpp.o
In file included from src/main.cpp:19:0:
.pio/libdeps/bluepill_f103c8/Ticker/Ticker.h:56:7: error: expected nested-name-specifier before 'fptr'
 using fptr = std::function<void()>;

Followed by the normal errors you would expect after that.

The problem may be at line 54 of Ticker.h, #if defined(__arm__) || defined(ESP8266) || defined(ESP32). I changed that area to just typedef void (*fptr)(); and then everything builds and runs ok.

I have not dug any deeper as that change is enough to keep me going but I figured you may wish to review the issue so it does not catch other people out.

If you need more detail just let me know what.

Member function as callback parameter

I'm a C++ noob and I'm having a hard time figuring out how to supply a member function as the callback parameter for the Ticker.

This code:

void Meep::myCallback() {
}

void Meep::init() {
    Ticker tickerMeep = Ticker(myCallback, 5000);
}

Gives me the error message error: no matching function for call to 'Ticker::Ticker(<unresolved overloaded function type>, int)'

Do you have any ideas how this could be achieved?

Thank you for the nice library which I'm using in almost every project now.

Functional callbacks work on Tensilica (ESP8266/32) too, not only ARM.

I tried your FunctionalARM.ino example and it also works fine on the Espressif Tensilica Chips.

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0018,len:4
load:0x3fff001c,len:1044
load:0x40078000,len:8896
load:0x40080400,len:5828
entry 0x400806ac

B::func: true.
A::func: true.
A::func: false.
B::func: true.
C(): 4.
func.
B::func: true.
C(): 4.
func.
A::func: true.
A::func: false.
C(): 4.
func.
A::func: true.
A::func: false.
B::func: true.
A::func: true.
A::func: false.
B::func: true.
C(): 4.
func.
B::func: true.

Work with ticker without calling ticker.update()

Hi guys I need your help, I needed to use ticker so initially i was using "https://github.com/esp8266/Arduino/tree/master/libraries/Ticker" but then i need a ticker for microsec which this library did not supported, so i came across by library another library by sstaub "https://github.com/sstaub/Ticker". Now this library needs a must call (object).update() called in loop other wise callback function is not called, unlike earlier there was no need for function like update in main loop... For example i need a ticker to blink LED while wifi is not connected and it is in loop WL_CONNECTED in void setup() and code has still not entered void loop(). So ticker callback is not called since it (Object).update() is in main loop. Is not possible to not use update like original ticker.h (ofc i dont only need to blink LED so dont give me an alternative to help me blink LED.)
This ticker has lot of advantages over old ticker and i need to use this library. So how can i get a work around? Thanks in Advance!
Best Regards!

interval() returning incorrect value

v4.4.0
Using MILLIS, returned interval is divided by 1000
Using MICROS, returned interval is 1000 times too high

Ticker.cpp, line 96:

uint32_t Ticker::interval() {
    if (resolution == MILLIS) return timer / 1000;
    else return timer;
}

Should that check be for MICROS rather than MILLIS?

Unstable when doing Serial.print(x) of an integer.

Unstable when doing Serial.print(x) of an integer. Unstable means the printf output is offset. The wifi sometimes will not connect. Wifi functions are not working.
If I remove the + HighLevelStatus2secCount, everything goes back to working program.

int HighLevelStatus2secCount=0;
int LowLevelStatus2secCount=0;
void RunPeriodicallyTicker();
Ticker timer5(RunPeriodicallyTicker, 2500, 0, MILLIS); // RunPeriodicallyTicker function will run every 2.5 seconds.
void setup() { 
//Wifi functions
  timer5.start();
}

void loop() {
//Body of program
}
void RunPeriodicallyTicker() {
  if (LevelStatus == HIGH) { //Float is High and 120VAC is not applied
      HighLevelStatus2secCount++;
      LowLevelStatus2secCount = 0;
      Serial.println("Float Switch Up! " + HighLevelStatus2secCount);
      if (HighLevelStatus2secCount>40){ //900 * 2.5seconds is equal to 37minutes roughly
        HighLevelStatus2secCount=0; //so that the number will not get too big and crash the microprocessor
        ProbableSumpPumpFailure(); //We need to send data to AWS Gateway that there could be Sump Pump Failure due to level did not go down within estimated time.
        
      }
    }

MICROS and MICROS_MICROS

I can't find an explanation between the two in your explanations.

if I understood the code correctly, by default "MICROS"
write "Ticker timer (printCounter, 1000, 0);"
& "Ticker timer (printCounter, 1000, 0, MICROS);"
it's identical, and 1000 is x1000 internally, so 1 second

Ticker timer (printCounter, 1000, 0, MICROS_MICROS);
it is 1000 microsecond (1ms) in this case, correct?
(with 4µs resolution for ATMega328 @ 16Mhs)

therefore MICROS, the duration is multiplied by 1000 internally,
if we are not careful, and logically we say to ourselves, since the resolution is microsecond, we make the mistake of thinking that 1000 is 1 millisecond

the most logical would have been to be in MILLIS by default (exactly like delay), and not to ask any questions.
and specify only MICROS for microsecond times but not multiply by 1000 internally.

your chosen solution does not make sense to me, but I am not criticizing.
it should just be explained correctly in the documentation

thank you again for your work

Endless repeat

Hello,
First of all, Thanks for this great library.
I would like to use it with an endless repeat, but after reading your code I think I found a minor bug (maybe I am wrong).
The problem I am seeing is that after an overflow of the counter variable, the loop will stop because repeat - counter = 1 will become true.
Of course this bug will only occur after a quite long time (depending on the ticker frequency), but is still there (and relatively easy to fix).
As I said maybe I made a mistake and you are taking care of somewhere I couldn't find.

Compilation Errors - Ticker example

Attempting to use the ticker library with a ESP8266 - WEMOS mini, but receiving compilation errors, so I tried the example in GitHub, still receiving errors:

c:/users/user/appdata/local/arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: sketch\Ticker.ino.cpp.o:(.text._Z12printCounterv+0xc): undefined reference to `Ticker::counter()'

c:/users/user/appdata/local/arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: sketch\Ticker.ino.cpp.o: in function `printCounter()':

c:\Users\user\Documents\Arduino\generated_examples\Ticker_2/Ticker.ino:41: undefined reference to `Ticker::counter()'

c:/users/user/appdata/local/arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: sketch\Ticker.ino.cpp.o: in function `printCountdown()':

c:\Users\user\Documents\Arduino\generated_examples\Ticker_2/Ticker.ino:46: undefined reference to `Ticker::counter()'

c:/users/user/appdata/local/arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: sketch\Ticker.ino.cpp.o:(.text.setup+0x10): undefined reference to `Ticker::start()'

c:/users/user/appdata/local/arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: sketch\Ticker.ino.cpp.o: in function `setup':

c:\Users\user\Documents\Arduino\generated_examples\Ticker_2/Ticker.ino:19: undefined reference to `Ticker::start()'

c:/users/user/appdata/local/arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: c:\Users\user\Documents\Arduino\generated_examples\Ticker_2/Ticker.ino:19: undefined reference to `Ticker::start()'

c:/users/user/appdata/local/arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: sketch\Ticker.ino.cpp.o: in function `setup':

C:\Users\user\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.1\cores\esp8266/HardwareSerial.h:76: undefined reference to `Ticker::start()'

c:/users/user/appdata/local/arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: C:\Users\user\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.1\cores\esp8266/HardwareSerial.h:76: undefined reference to `Ticker::start()'

c:/users/user/appdata/local/arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: sketch\Ticker.ino.cpp.o:c:\Users\user\Documents\Arduino\generated_examples\Ticker_2/Ticker.ino:22: more undefined references to `Ticker::start()' follow

c:/users/user/appdata/local/arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: sketch\Ticker.ino.cpp.o: in function `setup':

c:\Users\user\Documents\Arduino\generated_examples\Ticker_2/Ticker.ino:23: undefined reference to `Ticker::update()'

c:/users/user/appdata/local/arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: c:\Users\user\Documents\Arduino\generated_examples\Ticker_2/Ticker.ino:24: undefined reference to `Ticker::interval(unsigned int)'

c:/users/user/appdata/local/arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: c:\Users\user\Documents\Arduino\generated_examples\Ticker_2/Ticker.ino:25: undefined reference to `Ticker::update()'

c:/users/user/appdata/local/arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: c:\Users\user\Documents\Arduino\generated_examples\Ticker_2/Ticker.ino:26: undefined reference to `Ticker::update()'

c:/users/user/appdata/local/arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: c:\Users\user\Documents\Arduino\generated_examples\Ticker_2/Ticker.ino:27: undefined reference to `Ticker::update()'

c:/users/user/appdata/local/arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: sketch\Ticker.ino.cpp.o:(.text.loop+0x2f): undefined reference to `Ticker::update()'

c:/users/user/appdata/local/arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: sketch\Ticker.ino.cpp.o: in function `loop':

c:\Users\user\Documents\Arduino\generated_examples\Ticker_2/Ticker.ino:31: undefined reference to `Ticker::update()'

c:/users/user/appdata/local/arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: c:\Users\user\Documents\Arduino\generated_examples\Ticker_2/Ticker.ino:30: undefined reference to `Ticker::counter()'

c:/users/user/appdata/local/arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: c:\Users\user\Documents\Arduino\generated_examples\Ticker_2/Ticker.ino:32: undefined reference to `Ticker::interval(unsigned int)'

c:/users/user/appdata/local/arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: c:\Users\user\Documents\Arduino\generated_examples\Ticker_2/Ticker.ino:33: undefined reference to `Ticker::counter()'

c:/users/user/appdata/local/arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: c:\Users\user\Documents\Arduino\generated_examples\Ticker_2/Ticker.ino:35: undefined reference to `Ticker::interval(unsigned int)'

c:/users/user/appdata/local/arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: c:\Users\user\Documents\Arduino\generated_examples\Ticker_2/Ticker.ino:37: undefined reference to `Ticker::Ticker(void (*)(), unsigned int, unsigned int, resolution_t)'

c:/users/user/appdata/local/arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: c:\Users\user\Documents\Arduino\generated_examples\Ticker_2/Ticker.ino:38: undefined reference to `Ticker::Ticker(void (*)(), unsigned int, unsigned int, resolution_t)'

c:/users/user/appdata/local/arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: sketch\Ticker.ino.cpp.o: in function `_GLOBAL__sub_I_ledState':

c:\Users\user\Documents\Arduino\generated_examples\Ticker_2/Ticker.ino:12: undefined reference to `Ticker::Ticker(void (*)(), unsigned int, unsigned int, resolution_t)'

c:/users/user/appdata/local/arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: c:\Users\user\Documents\Arduino\generated_examples\Ticker_2/Ticker.ino:12: undefined reference to `Ticker::Ticker(void (*)(), unsigned int, unsigned int, resolution_t)'

c:/users/user/appdata/local/arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: c:\Users\user\Documents\Arduino\generated_examples\Ticker_2/Ticker.ino:13: undefined reference to `Ticker::Ticker(void (*)(), unsigned int, unsigned int, resolution_t)'

c:/users/user/appdata/local/arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: sketch\Ticker.ino.cpp.o:c:\Users\user\Documents\Arduino\generated_examples\Ticker_2/Ticker.ino:14: more undefined references to `Ticker::Ticker(void (*)(), unsigned int, unsigned int, resolution_t)' follow

c:/users/user/appdata/local/arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: sketch\Ticker.ino.cpp.o: in function `_GLOBAL__sub_I_ledState':

c:\Users\user\Documents\Arduino\generated_examples\Ticker_2/Ticker.ino:15: undefined reference to `Ticker::~Ticker()'

c:/users/user/appdata/local/arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: c:\Users\user\Documents\Arduino\generated_examples\Ticker_2/Ticker.ino:16: undefined reference to `Ticker::~Ticker()'

c:/users/user/appdata/local/arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: c:\Users\user\Documents\Arduino\generated_examples\Ticker_2/Ticker.ino:16: undefined reference to `Ticker::~Ticker()'

c:/users/user/appdata/local/arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: c:\Users\user\Documents\Arduino\generated_examples\Ticker_2/Ticker.ino:65: undefined reference to `Ticker::~Ticker()'

c:/users/user/appdata/local/arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: sketch\Ticker.ino.cpp.o:(.text.exit._GLOBAL__sub_D_ledState+0x27): undefined reference to `Ticker::~Ticker()'

c:/users/user/appdata/local/arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: sketch\Ticker.ino.cpp.o:c:\Users\user\Documents\Arduino\generated_examples\Ticker_2/Ticker.ino:16: more undefined references to `Ticker::~Ticker()' follow

collect2.exe: error: ld returned 1 exit status

Ticker compile error with ESP8266 in Arduino

Hi, when I compile using an Arduino board such as an Uno the sketch with your Ticker library compiles without error. However, when I switch to an ESP8266 board such as a Wemos mini I get the following error Ticker.cpp:27:15: error: expected constructor, destructor, or type conversion before '(' token 27 | Ticker::Ticker(fptr callback, uint32_t timer, uint32_t repeat, resolution_t resolution) { . Is there something I need to specify in the sketch to work with ESP boards?
Thanks

How to use library with a function which needs to run as fast as possible

Hi there. I have a function which reads sensor data from a serial device, but I want this to run as fast as possible, ie not scheduled. Then I have other slower functions which I would like to schedule using your library.

The sensor data I read from serial takes approx 100ms to execute making my loop time about 10Hz. The other tasks need to run at 300ms intervals, and another one at 10 second intervals.

Is this possible and how would I structure the code? Thank you.

Handling of time overflows

Looking at the code, I do not see anything that would ensure that tickers keep working correctly when the timer, whether micros() or millis(), used as its source of time information overflows. In such a case, how will tickers behave? Considering the micros() value overflows approximately every 70 minutes and the millis() value overflows approximately every 50 days according to the Arduino documentation, does this mean that this library is unusable or will behave incorrectly for any use case in which the Arduino remains running for more than those durations? Because the default source of time information is now micros(), this could be a particularly serious problem because it is probably not infrequent for Arduino programs containing repeating events to run for longer than 70 minutes.

Although there may be no perfect solution to this, a majority of uses will probably use a ticker interval far shorter than either of those overflow intervals. Using this assumption, it should be possible to modify the library to function correctly across a time overflow.

Here is some code which I have used in a similar situation to solve this kind of problem. Sorry if it is wrong or not applicable here.

double timeSinceLastUpdate = updateTime - lastUpdateTime;
if(timeSinceLastUpdate < 0) //if a time overflow has occurred
{
    timeSinceLastUpdate = updateTime + (largestUnsignedLong - lastUpdateTime);
}

Get time left until execution?

I see that there is a function to get the number of times it has been executed, but in my case I want to see how much time is left on the timer in order to be able to "top up" the timer again (remaining time + x as the new interval).

Is there any way to achieve this?

invalid use of non-static member function

    Door *doorBuff = sensors[switchNo]->getDoor();

    DEBUG_SERIAL.println("switch");
    DEBUG_SERIAL.println(switchNo);

    if (doorBuff->getDoorStatus() == false)
    {
        doorBuff->openDoor();
        Ticker openDoorTicker(doorBuff->openDoorDelay, MOTO_TIME, 1, MICROS);
        openDoorTicker.start();
    }
    else
    {
        doorBuff->closeDoor();
        Ticker closeDoorTicker(doorBuff->closeDoorDelay, MOTO_TIME, 1, MICROS);
        closeDoorTicker.start();
    }

How to identify if the Ticker has already been triggered at least once?

My goal is to identify whether Ticker has already been called to handle its interval().
That is, identifying the first ticker trigger and being able to manipulate the interval with interval().

Example: I would like a callback to fire at the very beginning of the loop execution and then every 300 seconds (5 minutes).
I currently use a global variable for this, but I would like to know if Ticker has any features or can implement some solution so that the global variable is not needed.
Ex:

Ticker uplink_TICKER(uplink_function, 10, 0, MILLIS);

bool first_uplink = true;

main { ... }

loop {

uplink_TICKER.update();

            if(first_uplink == true) {
            
                        first_uplink = false;
            
                        uplink_TICKER.resume();

                        uplink_TICKER.interval(300000);          
            }

}

millis and ticker at same time

Hi, I see in the source code this library use millis() and micros(), can I use millis and ticker at same time?
best regards

Change the function pointer to a std::function for class member callbacks

Hi,

Currently the callback logic seems to be focused on calling back global functions.
That is often what you want so it's definitely OK there!

However, i'm currently trying to incorporate ticker in a class of mine and want to call a member function in the callback. I can change the typedef you use to allow for that in my specific case, but it would be much nicer if it were just a std::function as this could then be done with std::bind or a lambda.

For you, all you have to do is find/replace fptr with std::function<void()>.
And remove the typedef.

It still works how you're used to working with Ticker, but allows class member callbacks now. And i'm sure of that as that's how i'm using Ticker now :)

Cheers,
Mark

Ticker Rescheduling

Hi, Thank you so much for this fantastic library.

I'm new to Arduino and ESP, and your library has helped a lot in my projects.

I would like to ask a question and make two suggestions (sorry if I write something stupid):

I tried the following execution with Ticker:
-> Flash the LED 1 time (On - 500ms / OFF - 500ms), and pause for 5 seconds (5000ms).
At first I had difficulty doing this with Ticker, but I came up with the following solution:

bool estado_blink_LED = true;

Ticker blink_LED_ticker(blink_LED, 500, 2, MILLIS);

void blink_LED();

void blink_LED() {
    digitalWrite(LED_BUILTIN, estado_blink_LED);
    estado_blink_LED = !estado_blink_LED;
  }

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {
// Blink for 500ms and pause for 5s, and repeat again.

blink_LED_ticker.update(); 
if(blink_LED_ticker.state() == 0 && blink_LED_ticker.elapsed() > 5000) { 
    blink_LED_ticker.resume();
  }
}

My question: Is there a simpler way to do this with Ticker?

My Suggestion: If there is no simpler way, would it be interesting to include an argument for rescheduling? I saw something similar to this in the repeatWhileEver function of the H4 library.
It would be something very useful to control LED, BUZZER (in special)...

Something like:

// Blink for 500ms and pause for 5s (repeatWhileEver)
Ticker blink_LED_repeatWhileEver(blink_LED, 500, 2, MILLIS, 5000);

library name

hello, can you name your library STicker for example?

Ticket already exists internally with esp8266 and esp32 and it makes incompatibilities to use one or the other.
and it is counterproductive which is the same name, it breaks the updates of the kernel and your library too.

if you think (like me) that your library is better and can replace their internal libraries request a replacement.

thank you very much for your excellent work

Request for information (mills/micros overflow issue is there/not)

Dear Sstaub

This is not an issue. i just wanted to know if mills() or Micros() overflow will not happen when i use this ticker?? using your library never misses a schedule/callback for life?? is code is developed in such a way that overflow of mills and micros will not miss any "call back"

is it safe to use?

im trying to implement this code in my water controller.
i feel my project is critical as this is going to be controlling 1hp motor ON and OFF. im using ticker to scan inputs for every 100ms and some inputs in 10ms and some inputs in 1000ms and based on those 3 inputs im switching ON and OFF my motor.

please release my anxiety. Thank you

Compile error on ARM Cortex M0 (Industruino D21G or Arduino Zero)

Hello and congratulations for the simplicity of your library!
I have a compilation error on the Cortex M0.
it seems that it has a different definition (different number of arguments) of the max/min functions that you are using in the header.

/home/andrei/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin/arm-none-eabi-g++ -mcpu=cortex-m0plus -mthumb -c -g -Os -w -std=gnu++11 -ffunction-sections -fdata-sections -fno-threadsafe-statics -nostdlib --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -w -x c++ -E -CC -DF_CPU=48000000L -DARDUINO=10813 -DARDUINO_SAMD_INDUSTRUINO_D21G -DARDUINO_ARCH_SAMD -D__SAMD21G18A__ -DUSB_VID=0x2E78 -DUSB_PID=0x804d -DUSBCON "-DUSB_MANUFACTURER=\"ES Gear Ltd.\"" "-DUSB_PRODUCT=\"Industruino D21G\"" -I/home/andrei/.arduino15/packages/arduino/tools/CMSIS/4.5.0/CMSIS/Include/ -I/home/andrei/.arduino15/packages/arduino/tools/CMSIS-Atmel/1.0.0/CMSIS/Device/ATMEL/ -I/home/andrei/.arduino15/packages/industruino/hardware/samd/1.0.1/cores/industruino -I/home/andrei/.arduino15/packages/industruino/hardware/samd/1.0.1/variants/industruino_d21g -I/home/andrei/Arduino/libraries/Indio/src -I/home/andrei/.arduino15/packages/industruino/hardware/samd/1.0.1/libraries/Wire -I/home/andrei/Arduino/libraries/I2C_EEPROM -I/home/andrei/Arduino/libraries/ArduinoMenu_library/src -I/home/andrei/Arduino/libraries/U8g2/src -I/home/andrei/Arduino/libraries/Ticker -I/home/andrei/.arduino15/packages/industruino/hardware/samd/1.0.1/libraries/SPI /home/andrei/.arduino15/packages/industruino/hardware/samd/1.0.1/libraries/SPI/SPI.cpp -o /dev/null -DARDUINO_LIB_DISCOVERY_PHASE
Generating function prototypes...
/home/andrei/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin/arm-none-eabi-g++ -mcpu=cortex-m0plus -mthumb -c -g -Os -w -std=gnu++11 -ffunction-sections -fdata-sections -fno-threadsafe-statics -nostdlib --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -w -x c++ -E -CC -DF_CPU=48000000L -DARDUINO=10813 -DARDUINO_SAMD_INDUSTRUINO_D21G -DARDUINO_ARCH_SAMD -D__SAMD21G18A__ -DUSB_VID=0x2E78 -DUSB_PID=0x804d -DUSBCON "-DUSB_MANUFACTURER=\"ES Gear Ltd.\"" "-DUSB_PRODUCT=\"Industruino D21G\"" -I/home/andrei/.arduino15/packages/arduino/tools/CMSIS/4.5.0/CMSIS/Include/ -I/home/andrei/.arduino15/packages/arduino/tools/CMSIS-Atmel/1.0.0/CMSIS/Device/ATMEL/ -I/home/andrei/.arduino15/packages/industruino/hardware/samd/1.0.1/cores/industruino -I/home/andrei/.arduino15/packages/industruino/hardware/samd/1.0.1/variants/industruino_d21g -I/home/andrei/Arduino/libraries/Indio/src -I/home/andrei/.arduino15/packages/industruino/hardware/samd/1.0.1/libraries/Wire -I/home/andrei/Arduino/libraries/I2C_EEPROM -I/home/andrei/Arduino/libraries/ArduinoMenu_library/src -I/home/andrei/Arduino/libraries/U8g2/src -I/home/andrei/Arduino/libraries/Ticker -I/home/andrei/.arduino15/packages/industruino/hardware/samd/1.0.1/libraries/SPI /tmp/arduino_build_506678/sketch/polisher_v2_ind.ino.cpp -o /tmp/arduino_build_506678/preproc/ctags_target_for_gcc_minus_e.cpp -DARDUINO_LIB_DISCOVERY_PHASE
In file included from /home/andrei/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/4.8.3-2014q1/arm-none-eabi/include/c++/4.8.3/bits/char_traits.h:39:0,
                 from /home/andrei/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/4.8.3-2014q1/arm-none-eabi/include/c++/4.8.3/string:40,
                 from /home/andrei/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/4.8.3-2014q1/arm-none-eabi/include/c++/4.8.3/stdexcept:39,
                 from /home/andrei/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/4.8.3-2014q1/arm-none-eabi/include/c++/4.8.3/array:38,
                 from /home/andrei/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/4.8.3-2014q1/arm-none-eabi/include/c++/4.8.3/tuple:39,
                 from /home/andrei/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/4.8.3-2014q1/arm-none-eabi/include/c++/4.8.3/functional:55,
                 from /home/andrei/Arduino/libraries/Ticker/Ticker.h:55,
                 from /home/andrei/Arduino/cms/polisher_v2_ind/polisher_v2_ind.ino:30:
/home/andrei/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/4.8.3-2014q1/arm-none-eabi/include/c++/4.8.3/bits/stl_algobase.h:239:56: error: macro "min" passed 3 arguments, but takes just 2
     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
                                                        ^
/home/andrei/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/4.8.3-2014q1/arm-none-eabi/include/c++/4.8.3/bits/stl_algobase.h:260:56: error: macro "max" passed 3 arguments, but takes just 2
     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
                                                        ^

run times error

this is my code

I want to print pt100 data 5 times every seconds, but this timer just printed 5 times after it will not print anything

#include <Arduino.h>
#include "DHTesp.h"
#include "Ticker.h"
#include <Wire.h>
#include <Adafruit_MAX31865.h>
#include <SPI.h>
#include <pt100rtd.h>
#ifdef ESP32
#pragma message(THIS EXAMPLE IS FOR ESP8266 ONLY!)
#error Select ESP8266 board.
#endif
#define C2F(c) ((9 * c / 5) + 32)

DHTesp dht;
int a;
unsigned long nowtime;
// CS, DI, DO, CLK D0, D1, D2, D3
Adafruit_MAX31865 max1 = Adafruit_MAX31865(16, 5, 4, 0);
pt100rtd PT100 = pt100rtd();
#define RREF      430.0
#define RNOMINAL  100.0

void send_hum_tem_data();
void read_rt_100_tem();

// Ticker timer1(send_hum_tem_data, 1000, 5);
Ticker timer2(read_rt_100_tem, 1000, 5);

void send_hum_tem_data(){
  char str[100];

  
  delay(dht.getMinimumSamplingPeriod());

  float humidity = dht.getHumidity();
  float temperature = dht.getTemperature();

  //用sprintf来格式化字符串,给n0的val属性赋值
  sprintf(str, "t16.txt=\"%.2f\"\xff\xff\xff", humidity);
  //把字符串发送出去
  Serial.print(str);

  //用sprintf来格式化字符串,给t0的txt属性赋值
  // sprintf(str, "t15.txt=\"%.2f\"\xff\xff\xff", temperature);
  //把字符串发送出去
  // Serial.print(str);
}

void setup() {
  // put your setup code here, to run once:
  //初始化串口
  Serial.begin(115200);
  max1.begin(MAX31865_4WIRE);
  dht.setup(D4, DHTesp::DHT11);
  
  //因为串口屏开机会发送88 ff ff ff,所以要清空串口缓冲区
  while (Serial.read() >= 0); //清空串口缓冲区
  // 启动定时器1
  // timer1.start();
  timer2.start();
}
void checkFault(void)
{
	// Check and print any faults
	uint8_t fault = max1.readFault();
	if (fault)
	{
		Serial.print("Fault 0x"); Serial.println(fault, HEX);
		if (fault & MAX31865_FAULT_HIGHTHRESH)
		{
			Serial.println("RTD High Threshold"); 
		}
		if (fault & MAX31865_FAULT_LOWTHRESH)
		{
			Serial.println("RTD Low Threshold"); 
		}
		if (fault & MAX31865_FAULT_REFINLOW)
		{
			Serial.println("REFIN- > 0.85 x Bias"); 
		}
		if (fault & MAX31865_FAULT_REFINHIGH)
		{
			Serial.println("REFIN- < 0.85 x Bias - FORCE- open"); 
		}
		if (fault & MAX31865_FAULT_RTDINLOW)
		{
			Serial.println("RTDIN- < 0.85 x Bias - FORCE- open"); 
		}
		if (fault & MAX31865_FAULT_OVUV)
		{
			Serial.println("Under/Over voltage"); 
		}
		max1.clearFault();
	}
}


void read_rt_100_tem()
{
  char str[100];
  uint16_t rtd, ohmsx100 ;
	uint32_t dummy ;
	float ohms, Tlut ;  
	float Tcvd, Tcube, Tpoly, Trpoly ;

	rtd = max1.readRTD();

	// fast integer math:
	// fits in 32 bits as long as (100 * RREF) <= 2^16,
	//  i.e., RREF must not exceed 655.35 ohms (heh).
	// TO DO: revise for 4000 ohm reference resistor needed by Pt1000 RTDs
 
	// Use uint16_t (ohms * 100) since it matches data type in lookup table.
	dummy = ((uint32_t)(rtd << 1)) * 100 * ((uint32_t) floor(RREF)) ;
	dummy >>= 16 ;
	ohmsx100 = (uint16_t) (dummy & 0xFFFF) ;

	// or use exact ohms floating point value.
	ohms = (float)(ohmsx100 / 100) + ((float)(ohmsx100 % 100) / 100.0) ;

	// Serial.print("rtd: 0x") ; Serial.print(rtd,HEX) ;
	// Serial.print(", ohms: ") ; Serial.println(ohms,2) ;
 
  // compare lookup table and common computational methods
  
	Tlut	= PT100.celsius(ohmsx100) ;			// NoobNote: LUT== LookUp Table
  sprintf(str, "t15.txt=\"%.2f\"\xff\xff\xff", Tlut);
  Serial.print(str);
	// Tcvd	= PT100.celsius_cvd(ohms) ; 		  	// Callendar-Van Dusen calc
	// Tcube	= PT100.celsius_cubic(ohms) ;		  	// Cubic eqn calc
	// Tpoly	= PT100.celsius_polynomial(ohms) ;      	// 5th order polynomial
	// Trpoly	= PT100.celsius_rationalpolynomial(ohms) ;	// ugly rational polynomial quotient
	
	// // report temperatures at 0.001C resolution to highlight methodological differences
	// Serial.print("Tlut   = ") ; Serial.print(Tlut  ,3) ; Serial.println(" C (exact)") ;
	// Serial.print("Tcvd   = ") ; Serial.print(Tcvd  ,3) ; Serial.println(" C") ;
	// Serial.print("Tcube  = ") ; Serial.print(Tcube ,3) ; Serial.println(" C") ;
	// Serial.print("Tpoly  = ") ; Serial.print(Tpoly ,3) ; Serial.println(" C") ;
	// Serial.print("Trpoly = ") ; Serial.print(Trpoly,3) ; Serial.println(" C") ;
  	// Serial.println();
  
	// checkFault() ;
}
void loop() {
  // timer1.update();
  timer2.update();
	// delay(5000) ;
}

Code may not work properly after running for 50 days straight

The timers are based on the millis() and micros() functions from arduino, but reading the description of the millis() function on the arduino reference page:

"Returns the number of milliseconds passed since the Arduino board began running the current program. This number will overflow (go back to zero), after approximately 50 days." (reference

I found that after 50 days this function will go back to zero, and the code may malfunction.

Callback name

Why can't I use NULL in place of a callback name? I don't need ticker to call any function. All I need is to get elapsed time (millis) from the moment I started the timer and nothing else.

excellent librairy

excellent librairy

STicker.zip

thousand thank you

I renamed its name to STicker (StaubTicker) so as not to have a conflict with the existing library under arduino and esp8266.
I also renamed internal variables by preceding them with a "_".
I added a function to change the value of "repeat" on the fly.

thank you again for this librairy

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.