![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
interrupt sample
main.cpp@0:a20448f74532, 2015-08-22 (annotated)
- Committer:
- rockstar
- Date:
- Sat Aug 22 10:33:50 2015 +0000
- Revision:
- 0:a20448f74532
interrupt sample
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rockstar | 0:a20448f74532 | 1 | #include "mbed.h" |
rockstar | 0:a20448f74532 | 2 | |
rockstar | 0:a20448f74532 | 3 | InterruptIn button(p5); //define and name the interrupt input |
rockstar | 0:a20448f74532 | 4 | DigitalOut led(LED1); |
rockstar | 0:a20448f74532 | 5 | DigitalOut flash(LED4); |
rockstar | 0:a20448f74532 | 6 | |
rockstar | 0:a20448f74532 | 7 | void ISR1() { //this is the response to interrupt, i.e. the ISR |
rockstar | 0:a20448f74532 | 8 | led = !led; |
rockstar | 0:a20448f74532 | 9 | } |
rockstar | 0:a20448f74532 | 10 | |
rockstar | 0:a20448f74532 | 11 | int main() { |
rockstar | 0:a20448f74532 | 12 | button.rise(&ISR1); // attach the address of the ISR function to the |
rockstar | 0:a20448f74532 | 13 | // interrupt rising edge |
rockstar | 0:a20448f74532 | 14 | while(1) { // continuous loop, ready to be interrupted |
rockstar | 0:a20448f74532 | 15 | flash = !flash; |
rockstar | 0:a20448f74532 | 16 | wait(1); |
rockstar | 0:a20448f74532 | 17 | } |
rockstar | 0:a20448f74532 | 18 | } |