9 years, 5 months 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.

Be the first to answer this question.