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

LowPowerTicker

LowPowerTicker class hierarchy

The LowPowerTicker class has the same methods as the Ticker class but operates in deep sleep mode and has less resolution. Use the LowPowerTicker interface to set up a recurring interrupt when you only need millisecond accuracy; it calls a function repeatedly and at a specified rate. Because the LowPowerTicker class can operate in deep sleep mode, it does not block deep sleep when active.

You can create any number of LowPowerTicker objects, allowing multiple outstanding interrupts at the same time. The function can be a static function, a member function of a particular object or a Callback object.

Warnings and notes

  • No blocking code in ISR: avoid any calls to wait, infinite while loops or blocking calls in general.

  • No printf, malloc or new in ISR: avoid any calls to bulky library functions. In particular, certain library functions (such as printf, malloc and new) are not re-entrant, and their behavior could be corrupted when called from an ISR.

LowPowerTicker class reference

Public Member Functions
template<typename F >
MBED_FORCEINLINE void attach (F &&func, float t)
 Attach a function to be called by the Ticker, specifying the interval in seconds. More...
void attach (Callback< void()> func, std::chrono::microseconds t)
 Attach a function to be called by the Ticker, specifying the interval in microseconds. More...
void attach_us (Callback< void()> func, us_timestamp_t t)
 Attach a function to be called by the Ticker, specifying the interval in microseconds. More...
void detach ()
 Detach the function. More...

LowPowerTicker example

Try this program to set up a LowPowerTicker to repeatedly invert an LED:

/*
 * Copyright (c) 2020 Arm Limited and affiliates.
 * SPDX-License-Identifier: Apache-2.0
 */

#include "mbed.h"

LowPowerTicker flipper;
DigitalOut led1(LED1);

void flip()
{
    led1 = !led1;
}

int main()
{
    led1 = 1;
    flipper.attach(&flip, 2.0); // the address of the function to be attached (flip) and the interval (2 seconds)

    while (1) {
        ThisThread::sleep_for(200);
    }
}

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.