Use of interrupts example for NMHU ambient computing class Sp2015. Shows input pin and timer type interrupts.
main.cpp@0:912303e63cbd, 2014-02-21 (annotated)
- Committer:
- bcostm
- Date:
- Fri Feb 21 12:53:03 2014 +0000
- Revision:
- 0:912303e63cbd
- Child:
- 1:65b0e488f02a
Initial version.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bcostm | 0:912303e63cbd | 1 | #include "mbed.h" |
bcostm | 0:912303e63cbd | 2 | |
bcostm | 0:912303e63cbd | 3 | InterruptIn mybutton(USER_BUTTON); |
bcostm | 0:912303e63cbd | 4 | DigitalOut myled(LED1); |
bcostm | 0:912303e63cbd | 5 | |
bcostm | 0:912303e63cbd | 6 | float delay = 1.0; // 1 sec |
bcostm | 0:912303e63cbd | 7 | |
bcostm | 0:912303e63cbd | 8 | void pressed() |
bcostm | 0:912303e63cbd | 9 | { |
bcostm | 0:912303e63cbd | 10 | if (delay == 1.0) |
bcostm | 0:912303e63cbd | 11 | delay = 0.2; // 200 ms |
bcostm | 0:912303e63cbd | 12 | else |
bcostm | 0:912303e63cbd | 13 | delay = 1.0; // 1 sec |
bcostm | 0:912303e63cbd | 14 | } |
bcostm | 0:912303e63cbd | 15 | |
bcostm | 0:912303e63cbd | 16 | int main() |
bcostm | 0:912303e63cbd | 17 | { |
bcostm | 0:912303e63cbd | 18 | mybutton.fall(&pressed); |
bcostm | 0:912303e63cbd | 19 | while (1) { |
bcostm | 0:912303e63cbd | 20 | myled = !myled; |
bcostm | 0:912303e63cbd | 21 | wait(delay); |
bcostm | 0:912303e63cbd | 22 | } |
bcostm | 0:912303e63cbd | 23 | } |