
Timeout e interrupciones
Revision 0:00e36fb49aa5, committed 2017-03-09
- Comitter:
- jangelgm
- Date:
- Thu Mar 09 21:45:17 2017 +0000
- Commit message:
- Timeout e interrupciones
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 |
diff -r 000000000000 -r 00e36fb49aa5 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Mar 09 21:45:17 2017 +0000 @@ -0,0 +1,38 @@ +/*Program Example 9.7: Demonstrates the use of Timeout and interrupts, to allow response +to an event-driven task while a time-driven task continues. +*/ +#include "mbed.h" +void blink_end (void); +void blink (void); +void ISR1 (void); +DigitalOut led1(LED1); +DigitalOut led2(LED2); +DigitalOut led3(LED3); +Timeout Response; //create a Timeout, and name it Response +Timeout Response_duration; //create a Timeout, and name it Response_duration +InterruptIn button(p5); //create an interrupt input, named button +void blink() //This function is called when Timeout is complete +{ + led2=1; +// set the duration of the led blink, with another timeout, duration 1 s + Response_duration.attach(&blink_end, 1); +} +void blink_end() //A function called at the end of Timeout Response_duration +{ + led2=0; +} +void ISR1() +{ + led3=1; //shows button is pressed; diagnostic and not central to program +//attach blink1 function to Response Timeout, to occur after 2 seconds + Response.attach(&blink, 2.0); +} +int main() +{ + button.rise(&ISR1); //attach the address of ISR1 function to the rising edge + while(1) { + led3=0; //clear LED3 + led1=!led1; + wait(0.2); + } +} \ No newline at end of file
diff -r 000000000000 -r 00e36fb49aa5 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Thu Mar 09 21:45:17 2017 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/6c34061e7c34 \ No newline at end of file