Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
10 years ago.
Ticker weirdness on nrf51822
I've seen some other posts on this subject but my problem is a little different. When the user pushes a button, I start advertising and blink an led during advertising.
The code is pretty boiler-plate:
<<code>>
Ticker t;
DigitalOut led1(LED1);
void toggleLed() { led1 = !led1; }
void buttonPressed() { t.attach(&toggleLed, 0.5); ble.startAdvertising(); }
void onAdvertTimeout() { t.detach(); } <</code>
What happens is that the code works the first time as expected. But if the advertising times out and the user presses the button again the advertising starts up again but the led doesn't blink (it's almost as if the detach() call is deleting the Ticker). In another display of weirdness, moving the t.attach() statement below the startAdvertising() call causes the led to remain lit on the first button press.
I am using Nordic's nrf51822-mkit board.