Timeout

Dependencies:   mbed

Revision:
0:5129d7da056e
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Oct 31 10:36:25 2016 +0000
@@ -0,0 +1,28 @@
+/*Program Example 5: Demonstrates Timeout, by triggering an event a fixed duration after a button press.
+*/
+#include "mbed.h"
+Timeout Response; //create a Timeout, and name it "Response"
+DigitalIn button (PC_13);
+DigitalOut led1(LED1);
+DigitalOut led2(D5);
+DigitalOut led3(D6);
+
+void blink(){
+    led2=1;
+    wait(1);
+    led2=0;
+}
+
+int main() {
+    //this function is called at the end of the Timeout
+    while(1){
+        if(button==0){
+            Response.attach(&blink,2.0); // attach blink function to Response Timeout, to occur after 2 seconds
+            led3=1; //shows button has been pressed
+        } else {
+            led3=0; 
+        }
+        led1=!led1;
+        wait(0.2);
+    }
+}
\ No newline at end of file