I want to use the Ticker library of the ESP8266 Arduino core to (asynchronously) delay the switch of a pin to a desired state like below. I am not sure about the "here is" function definitions and I am having a hard time to find some documentation. Please have a look at what I tried so far:
#include <Ticker.h>
Ticker change_pin;
...
uint8_t desired_state = 1;
...
change_pin.attach_ms(100, [](uint8_t state_to_change_to){
if( digitalRead(PIN) != state_to_change_to ) {
digitalWrite(PIN, state_to_change_to);
}
else {
change_pin.detach();
}
}, desired_state);
But the compiler's yelling:
espIKEA:145: error: no matching function for call to 'Ticker::attach_ms(int, toogle_light(uint8_t)::__lambda0, uint8_t&)'
}, des_state);
^
...
C:\Users\USER\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0\libraries\Ticker/Ticker.h:45:7: note: candidate expects 2 arguments, 3 provided
C:\Users\USER\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0\libraries\Ticker/Ticker.h:62:7: note: template<class TArg> void Ticker::attach_ms(uint32_t, void (*)(TArg), TArg)
void attach_ms(uint32_t milliseconds, void (*callback)(TArg), TArg arg)
^
C:\Users\USER\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0\libraries\Ticker/Ticker.h:62:7: note: template argument deduction/substitution failed:
C:\Users\USER\Documents\Arduino\Scratch\pintest\pintest.ino:145:15: note: mismatched types 'void (*)(TArg)' and 'toogle_light(u8)::__lambda0'
}, des_state);
^
So, I am having too few knowledge to understand what to do about it. I really would like to avoid having a separate function for the callback body.
PS: Important source file can be found here: Ticker.h