ENSMM / Mbed 2 deprecated Timeout

Dependencies:   mbed

Fork of Timeout by Joël Imbaud

Revision:
0:7a0f7fbc736b
Child:
1:50617d33bd51
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Main.cpp	Tue Jan 08 10:23:12 2019 +0000
@@ -0,0 +1,27 @@
+/* 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) {
+            }
+           }
\ No newline at end of file