Recently changed pages
Jobs Jobs
Debugging Debugging
mbed NXP LPC1768 mbed NXP LPC1768
Homepage Homepage
Compiler Tour Compiler Tour
Media Media
Serial Serial
From the mbed microcontroller Handbook.

Timeout

The Timeout interface is used to setup an interrupt to call a function after a specified delay.

Any number of Timeout objects can be created, allowing multiple outstanding interrupts at the same time.

Hello World!

A simple program to setup a Timeout to invert an LED after a given timeout...

Code

#include "mbed.h"

Timeout 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);
    }
}

API

API summary

TimeoutA Timeout is used to call a function at a point in the future
Functions
attachAttach a function to be called by the Timeout, specifiying the delay in seconds
attachAttach a member function to be called by the Timeout, specifiying the delay in seconds
attach_usAttach a function to be called by the Timeout, specifiying the delay in micro-seconds
attach_usAttach a member function to be called by the Timeout, specifiying the delay in micro-seconds
detachDetach the function
class Timeout : public Ticker
A Timeout is used to call a function at a point in the future
void attach(void (*fptr)(void),
float t)
Attach a function to be called by the Timeout, specifiying the delay in seconds
void attach_us(void (*fptr)(void),
unsigned int t)
Attach a function to be called by the Timeout, specifiying the delay in micro-seconds
void detach()
Detach the function



calendar Page history
Last modified 21 Jul 2010, by user avatar Dan Ros   tag No tags | 0 replies     Share: Digg Tweet This

Please login to post comments.