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

LowPowerTimeout

LowPowerTimeout class hierarchy

Use the LowPowerTimeout interface to set up an interrupt to call a function after a specified delay. You can create any number of LowPowerTimeout objects. This allows multiple outstanding interrupts at the same time. For more information about power management, please see our power management APIs.

Notes

  • No blocking code in ISR: Avoid any call to wait, infinite while loop or blocking calls in general.
  • No printf, malloc or new in ISR: Avoid any call 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.

LowPowerTimeout 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...
template<typename T , typename M >
void attach (T *obj, M method, float t)
 Attach a member function to be called by the Ticker, specifying the interval in seconds. 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...
template<typename T , typename M >
void attach_us (T *obj, M method, us_timestamp_t t)
 Attach a member function to be called by the Ticker, specifying the interval in microseconds. More...
void detach ()
 Detach the function. More...
Static Public Member Functions
static void irq (uint32_t id)
 The handler registered with the underlying timer interrupt. More...

LowPowerTimeout example

Set up a time out to invert an LED after a given time:

/* mbed Example Program
 * Copyright (c) 2006-2014 ARM Limited
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#include "mbed.h"
 
LowPowerTimeout flipper;
DigitalOut led1(LED1);
DigitalOut led2(LED2);
 
void flip() {
    led2 = !led2;
}
 
int main() {
    led2 = 1;
    flipper.attach(&flip, 2.0); // setup flipper to call flip after 2 seconds
 
    // spin in a main loop. flipper will interrupt it to call flip
    while(1) {
        led1 = !led1;
        wait(0.2);
    }
}
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.