8 years, 8 months ago.

Change Ticker interval/timeout/delay at runtime?

Hi Guys,

Could someone please let me know if its possible to change the interval which is attached to the ticker on runtime based on some conditions?

Thanks and Regards, Neil

1 Answer

8 years, 8 months ago.

You sure can. Here's a code snippet I just tested on a K64F:

#include "mbed.h"
 
Ticker tick;
 
DigitalOut myled(LED1, 0);
 
void flip(void) { // flip function
    myled = !myled;
}
 
int main() {

    while(1) {
        tick.attach(&flip, 0.25);
        wait(5);   
        tick.detach();
        
        tick.attach(&flip, 1);
        wait(5);   
        tick.detach();
    }
}

Accepted Answer