6 years, 8 months ago.

LowPowerTimeout

What does LowPowerTimeout stand for ? In the source code, it is a sub-class of LowPowerTicker, which is sub-class of Ticker. Then why mbed have two similiar classes ?

And there are no demo code how to use that. It seems we should add a callback for LowPowerTimeout ?

1 Answer

6 years, 8 months ago.

A Timeout calls some once function after a specified time interval, while a Ticker will call a function at a recurring interval.

You can view their class references here - https://docs.mbed.com/docs/mbed-os-api/en/mbed-os-5.5/api/classmbed_1_1LowPowerTimeout.html

You can use the LowPowerTicker's attach function to specify the callback, the following code example will turn on an LED after 2 seconds:

#include "mbed.h"

DigitalOut led1(LED1);
LowPowerTimeout timeout;
void set_led() {
    led1  = 0;
}

int main() {
    led1 = 1; // Turn off LED
    // Call set_led after 2 seconds 
    timeout.attach(&set_led, 2);
    while(1);
}

Accepted Answer