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.
5 years 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?
1 Answer
5 years 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; LEDTimer.attach(&turnOff,time); }
Can you add your code (use the 'editing tips' to see how).
Try a Ticker first, see here:
https://os.mbed.com/docs/mbed-os/v5.11/apis/ticker.html
posted by Paul Staron 09 Apr 2019