Mistake on this page?
Report an issue in GitHub or email us


Wait functions provide simple wait capabilities. The OS scheduler puts the current thread in waiting state, allowing another thread to execute. Even better: If there are no other threads in ready state, it can put the whole microcontroller to sleep, saving energy.

/** Waits for a number of seconds, with microsecond resolution (within
 *  the accuracy of single precision floating point).
 *  @param s number of seconds to wait
void wait(float s);

/** Waits a number of milliseconds.
 *  @param ms the whole number of milliseconds to wait
void wait_ms(int ms);

/** Waits a number of microseconds.
 *  @param us the whole number of microseconds to wait
void wait_us(int us);

Avoiding OS delay

When you call wait, your board's CPU is in a loop waiting for the required time to pass. Using the Arm Mbed RTOS, you can make a call to Thread::wait instead.


 #include "mbed.h"

 DigitalOut heartbeat(LED1);

 int main() {
     while (1) {
         heartbeat = 1;
         heartbeat = 0;

Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.