by Rob Toulson and Tim Wilmshurst from textbook "Fast and Effective Embedded Systems Design: Applying the ARM mbed"

Dependencies:   mbed

Committer:
robt
Date:
Fri May 24 21:48:28 2013 +0000
Revision:
0:a4095d77cfff
by Rob Toulson and Tim Wilmshurst from textbook "Fast and Effective Embedded Systems Design: Applying the ARM mbed"

Who changed what in which revision?

UserRevisionLine numberNew contents of line
robt 0:a4095d77cfff 1 /*Program Example 9.6: Demonstrates Timeout, by triggering an event a fixed duration after a button press. */
robt 0:a4095d77cfff 2
robt 0:a4095d77cfff 3 #include "mbed.h"
robt 0:a4095d77cfff 4 Timeout Response; //create a Timeout, and name it "Response"
robt 0:a4095d77cfff 5 DigitalIn button (p5);
robt 0:a4095d77cfff 6 DigitalOut led1(LED1);
robt 0:a4095d77cfff 7 DigitalOut led2(LED2);
robt 0:a4095d77cfff 8 DigitalOut led3(LED3);
robt 0:a4095d77cfff 9
robt 0:a4095d77cfff 10 void blink() { //this function is called at the end of the Timeout
robt 0:a4095d77cfff 11 led2 = 1;
robt 0:a4095d77cfff 12 wait(0.5);
robt 0:a4095d77cfff 13 led2=0;
robt 0:a4095d77cfff 14 }
robt 0:a4095d77cfff 15
robt 0:a4095d77cfff 16 int main() {
robt 0:a4095d77cfff 17 while(1) {
robt 0:a4095d77cfff 18 if(button==1){
robt 0:a4095d77cfff 19 Response.attach(&blink,2.0); // attach blink function to Response Timeout,
robt 0:a4095d77cfff 20 //to occur after 2 seconds
robt 0:a4095d77cfff 21 led3=1; //shows button has been pressed
robt 0:a4095d77cfff 22 }
robt 0:a4095d77cfff 23 else {
robt 0:a4095d77cfff 24 led3=0;
robt 0:a4095d77cfff 25 }
robt 0:a4095d77cfff 26 led1=!led1;
robt 0:a4095d77cfff 27 wait(0.2);
robt 0:a4095d77cfff 28 }
robt 0:a4095d77cfff 29 }
robt 0:a4095d77cfff 30