Juan Angel García
/
9_1
Interrupción simple
main.cpp@0:b5b34c86553e, 2017-03-09 (annotated)
- Committer:
- jangelgm
- Date:
- Thu Mar 09 21:40:13 2017 +0000
- Revision:
- 0:b5b34c86553e
Interrupci?n simple.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jangelgm | 0:b5b34c86553e | 1 | /* Program Example 9.1: Simple interrupt example. External input causes interrupt, |
jangelgm | 0:b5b34c86553e | 2 | while led flashes |
jangelgm | 0:b5b34c86553e | 3 | */ |
jangelgm | 0:b5b34c86553e | 4 | #include "mbed.h" |
jangelgm | 0:b5b34c86553e | 5 | InterruptIn button(p5); //define and name the interrupt input |
jangelgm | 0:b5b34c86553e | 6 | DigitalOut led(LED1); |
jangelgm | 0:b5b34c86553e | 7 | DigitalOut flash(LED4); |
jangelgm | 0:b5b34c86553e | 8 | void ISR1() //this is the response to interrupt, i.e. the ISR |
jangelgm | 0:b5b34c86553e | 9 | { |
jangelgm | 0:b5b34c86553e | 10 | led = !led; |
jangelgm | 0:b5b34c86553e | 11 | } |
jangelgm | 0:b5b34c86553e | 12 | int main() |
jangelgm | 0:b5b34c86553e | 13 | { |
jangelgm | 0:b5b34c86553e | 14 | button.rise(&ISR1); // attach the address of the ISR function to the |
jangelgm | 0:b5b34c86553e | 15 | // interrupt rising edge |
jangelgm | 0:b5b34c86553e | 16 | while(1) { // continuous loop, ready to be interrupted |
jangelgm | 0:b5b34c86553e | 17 | flash = !flash; |
jangelgm | 0:b5b34c86553e | 18 | wait(0.25); |
jangelgm | 0:b5b34c86553e | 19 | } |
jangelgm | 0:b5b34c86553e | 20 | } |