2 years, 7 months ago.

How to use a timer as a wait function?

Im trying to write a code in MBED on my nucleo where a certain action has to be done for 1 second, and then it has to go back to the 'vooruit' case. i can't use a wait function because that will stop my entire code from working, so i have to use a timer or something else. In the picture u can see my current code which doesn't work. All i need is that once the "1" case starts, that the LED goes out for one second using a timer and then it switches back to the case above. Can anyone help me?

Can you add your code (use the 'editing tips' to see how).

Try a Ticker first, see here:


posted by Paul Staron 09 Apr 2019

1 Answer

2 years, 7 months ago.

It's hard to tell without seeing your code but probably all you need is something like this:

Timeout LEDTimer;

void turnOff(void) {
  led = 0;

// turns the LED on for the time given.
void turnOnForTime(float time) {
  led = 1;