button trigger interrupt 20160528
Fork of Nucleo_read_button_interrupt by
main.cpp@2:4103c09a0f63, 2016-05-28 (annotated)
- Committer:
- ittraining
- Date:
- Sat May 28 07:34:08 2016 +0000
- Revision:
- 2:4103c09a0f63
- Parent:
- 1:19e910fda737
test by jo
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 | |
ittraining | 1:19e910fda737 | 8 | void pressed_down() |
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 | } |
ittraining | 1:19e910fda737 | 15 | |
ittraining | 1:19e910fda737 | 16 | |
bcostm | 0:912303e63cbd | 17 | |
bcostm | 0:912303e63cbd | 18 | int main() |
bcostm | 0:912303e63cbd | 19 | { |
ittraining | 2:4103c09a0f63 | 20 | mybutton.fall(&pressed_down); |
ittraining | 2:4103c09a0f63 | 21 | // mybutton.rise(&pressed_down); |
bcostm | 0:912303e63cbd | 22 | while (1) { |
bcostm | 0:912303e63cbd | 23 | myled = !myled; |
bcostm | 0:912303e63cbd | 24 | wait(delay); |
bcostm | 0:912303e63cbd | 25 | } |
bcostm | 0:912303e63cbd | 26 | } |