Timeout
Dependencies: mbed
Revision 0:5129d7da056e, committed 2016-10-31
- Comitter:
- MDevolution
- Date:
- Mon Oct 31 10:36:25 2016 +0000
- Commit message:
- Esercitazione5_5
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
--- /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
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Mon Oct 31 10:36:25 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/9bcdf88f62b0 \ No newline at end of file