Hi, there.
I’m creating a library, and would like to make use of the Ticker library from it. But apparently the function attach (from the Ticker library) expects a callback into another function. It works fine from a sketch. But how do I pass this on from another library? What is the syntax for doing this from a class?
This is a part of my header file:
#ifndef konnec_h
#define konnec_h
#include "Arduino.h"
#define ledB 12
class Ticker;
class Konnec {
public:
void openAP();
void begin();
private:
Ticker *_ticker = NULL;
void tick();
}
And this is part of my .cpp file:
#include <konnec.h>
#include "Arduino.h"
#include <Ticker.h>
void Konnec::begin() {
_ticker = new Ticker();
}
void Konnec::tick() { //This is the funcion I'd like to Ticker library to execute
//toggle state
byte state = digitalRead(ledB);
digitalWrite(ledB, !state);
}
void Konnec::openAP() { //This is the function where I'd to attach the ticker
_ticker->attach(0.6, tick);
}
This is the error I get:
Compiling 'HomeCenter_v20' for 'NodeMCU 1.0 (ESP-12E Module)'
konnec.cpp:In member function 'void Konnec::openAP()
konnec.cpp:141:27: error: no matching function for call to 'Ticker::attach(double, <unresolved overloaded function type>)
:_ticker->attach(0.6, tick)
konnec.cpp:candidates are
konnec.cpp:In file included from
Ticker.h:callback_t)
:void attach(float seconds, callback_t callback)
Ticker.h:callback_t {aka void (*)()}
Ticker.h:attach(float, void (*)(TArg), TArg)
:void attach(float seconds, void (*callback)(TArg), TArg arg)
Ticker.h:template argument deduction\substitution failed
konnec.cpp:*)()
:_ticker->attach(0.6, tick)
konnec.cpp:tick
Error compiling libraries
But if I change the implementation to:
void Konnec::openAP() { //This is the function where I wanna attach the ticker
_ticker->attach(0.6, tick());
}
I get this error:
Compiling 'HomeCenter_v20' for 'NodeMCU 1.0 (ESP-12E Module)'
konnec.cpp:In member function 'void Konnec::openAP()
konnec.cpp:141:29: error: invalid use of void expression
:_ticker->attach(0.6, tick())
Error compiling libraries
Can anybody please help?