I am trying to use the Ticker library and while the example works fine I am having an issue with getting it to work when I have a void function with parameters.
See code example below (which does not worK)
#include "Ticker.h"
void printMessage(int a, int b);
Ticker timer1(printMessage, 0, 1);
void setup()
{
pinMode(LED_BUILTIN, OUTPUT);
Serial.begin(9600);
delay(2000);
timer1.start();
printMessage(1, 1);
}
void loop()
{
timer1.update();
}
void printMessage(int a, int b)
{
if (a == 1 && b == 1)
{
Serial.println("Hello!");
}
else
{
Serial.println("Goodbye");
}
}
and this the error I get at compile
Arduino: 1.8.15 (Windows 10), Board: "LOLIN(WEMOS) D1 R2 & mini, 80 MHz, Flash, Legacy (new can return nullptr), All SSL ciphers (most compatible), 4MB (FS:2MB OTA:~1019KB), v2 Lower Memory, Disabled, None, Only Sketch, 921600"
Ticker:5:33: error: no matching function for call to 'Ticker::Ticker(void (&)(int, int), int, int)'
Ticker timer1(printMessage, 0, 1);
^
C:\Users\proie\AppData\Local\Temp\arduino_modified_sketch_811228\Ticker.ino:5:33: note: candidates are:
In file included from C:\Users\proie\AppData\Local\Temp\arduino_modified_sketch_811228\Ticker.ino:1:0:
C:\Users\proie\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.3\libraries\Ticker\src/Ticker.h:32:5: note: Ticker::Ticker()
Ticker();
^
C:\Users\proie\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.3\libraries\Ticker\src/Ticker.h:32:5: note: candidate expects 0 arguments, 3 provided
C:\Users\proie\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.3\libraries\Ticker\src/Ticker.h:29:7: note: Ticker::Ticker(const Ticker&)
class Ticker
^
C:\Users\proie\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.3\libraries\Ticker\src/Ticker.h:29:7: note: candidate expects 1 argument, 3 provided
C:\Users\proie\AppData\Local\Temp\arduino_modified_sketch_811228\Ticker.ino: In function 'void setup()':
Ticker:13:10: error: 'class Ticker' has no member named 'start'
timer1.start();
^
C:\Users\proie\AppData\Local\Temp\arduino_modified_sketch_811228\Ticker.ino: In function 'void loop()':
Ticker:19:10: error: 'class Ticker' has no member named 'update'
timer1.update();
^
Multiple libraries were found for "Ticker.h"
Used: C:\Users\proie\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.3\libraries\Ticker
Not used: C:\Users\proie\Dropbox\ARDUINO\arduino 1.8.9\libraries\Ticker
Not used: C:\Users\proie\Dropbox\ARDUINO\arduino 1.8.9\libraries\Ticker-master
exit status 1
no matching function for call to 'Ticker::Ticker(void (&)(int, int), int, int)'
Am I missing something as the examples given does not have a void function with parameters.
What type of Arduino board are you using? The library does not support callbacks with parameters for AVR-based boards. But, if it's ARM or ESP-based, you can specify the callback using std::function and bind an argument to it using std::bind. From Ticker.h:
Looking at the compile error message i noticed this
Used: C:\Users\proie\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.3\libraries\Ticker
Not used: C:\Users\proie\Dropbox\ARDUINO\arduino 1.8.9\libraries\Ticker
Not used: C:\Users\proie\Dropbox\ARDUINO\arduino 1.8.9\libraries\Ticker-master
Does this mean the ticker library comes with the esp package so there is no need to download and install in my library?
It probably means you have the library installed in too many places. You're also using an old version of the Arduino IDE (1.8.9) latest is v1.8.19.
Also, you haven't answered:
EDIT:
It does indeed look like there's an ESP8266-specific version of Ticker (by a different author) in the ESP8266 core. It's API is incompatible with the one installed by the Arduino IDE's Library Manager.