![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
button trigger interrupt 20160528
Fork of Nucleo_read_button_interrupt by
main.cpp@1:19e910fda737, 2016-05-05 (annotated)
- Committer:
- ittraining
- Date:
- Thu May 05 03:36:22 2016 +0000
- Revision:
- 1:19e910fda737
- Parent:
- 0:912303e63cbd
- Child:
- 2:4103c09a0f63
button interrupt;
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 | 1:19e910fda737 | 20 | // mybutton.fall(&pressed_down); |
ittraining | 1:19e910fda737 | 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 | } |