ENSMM / Mbed 2 deprecated Timeout

Dependencies:   mbed

Fork of Timeout by Joël Imbaud

Main.cpp

Committer:
jimbaud
Date:
2019-01-08
Revision:
0:7a0f7fbc736b
Child:
1:50617d33bd51

File content as of revision 0:7a0f7fbc736b:

/* https://os.mbed.com/docs/v5.7/reference/timer.html

Use the Timeout interface to set up an interrupt to call a function after a specified delay.
You can create any number of Timeout objects, allowing multiple outstanding interrupts at the same time.
Warnings and notes
Timers are based on 32-bit int microsecond counters, so they can only time up to a maximum of 2^31-1 microseconds (30 minutes). They are designed for times between microseconds and seconds. For longer times, you should consider the time() real time clock.
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.
*/

#include "mbed.h"

Timeout flipper;
DigitalOut led1(LED1);

void flip() {
            led1 = !led1;
            }

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) {
            }
           }