by Rob Toulson and Tim Wilmshurst from textbook "Fast and Effective Embedded Systems Design: Applying the ARM mbed"
main.cpp@0:b3db09a98287, 2013-05-24 (annotated)
- Committer:
- robt
- Date:
- Fri May 24 21:46:57 2013 +0000
- Revision:
- 0:b3db09a98287
by Rob Toulson and Tim Wilmshurst from textbook "Fast and Effective Embedded Systems Design: Applying the ARM mbed"
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
robt | 0:b3db09a98287 | 1 | /* Program Example 9.1: Simple interrupt example. External input causes interrupt, while led flashes |
robt | 0:b3db09a98287 | 2 | */ |
robt | 0:b3db09a98287 | 3 | #include "mbed.h" |
robt | 0:b3db09a98287 | 4 | InterruptIn button(p5); //define and name the interrupt input |
robt | 0:b3db09a98287 | 5 | DigitalOut led(LED1); |
robt | 0:b3db09a98287 | 6 | DigitalOut flash(LED4); |
robt | 0:b3db09a98287 | 7 | |
robt | 0:b3db09a98287 | 8 | void ISR1() { //this is the response to interrupt, i.e. the ISR |
robt | 0:b3db09a98287 | 9 | led = !led; |
robt | 0:b3db09a98287 | 10 | } |
robt | 0:b3db09a98287 | 11 | |
robt | 0:b3db09a98287 | 12 | int main() { |
robt | 0:b3db09a98287 | 13 | button.rise(&ISR1); // attach the address of the ISR function to the |
robt | 0:b3db09a98287 | 14 | // interrupt rising edge |
robt | 0:b3db09a98287 | 15 | while(1) { // continuous loop, ready to be interrupted |
robt | 0:b3db09a98287 | 16 | flash = !flash; |
robt | 0:b3db09a98287 | 17 | wait(0.25); |
robt | 0:b3db09a98287 | 18 | } |
robt | 0:b3db09a98287 | 19 | } |
robt | 0:b3db09a98287 | 20 |