Timeout
Dependencies: mbed
main.cpp
- Committer:
- MDevolution
- Date:
- 2016-10-31
- Revision:
- 0:5129d7da056e
File content as of revision 0:5129d7da056e:
/*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); } }