Hi!
I’m not sure if this is a bug or if things are supposed to work this way - if they are, the documentation should definitely be more clear.
Basically, when declaring a ticker object inside of main
, it does not work. I made a simple program to demonstrate what I mean: in the code below, LED2 will flash while LED1 will not. The behavior is the same if I switch them - basically, the ticker declared in global scope works while the one declared locally doesn’t. Why is that the case?
The below code was run on a NUCLEO-H743ZI2, compiled with arm-none-eabi-g++ (15:9-2019-q4-0ubuntu1) 9.2.1
and MBed OS 6.1.0 stable
.
Code:
#include <mbed.h>
// setup
DigitalOut led1(LED1);
DigitalOut led2(LED2);
void led1Callback() {
led1 = !led1;
}
void led2Callback() {
led2 = !led2;
}
// real test
Ticker tickerG;
int main() {
Ticker tickerL;
tickerL.attach(callback(&led2Callback), 1); // doesn't work
tickerG.attach(callback(&led1Callback), 1); // works
}