Hieu Vo
/
NUCLEO_BTN_LED_DEMO
Simple firmware to test the I/O capabilities of a Nucleo 64 board
Revision 1:69c43e344369, committed 2016-03-15
- Comitter:
- hieuvt6
- Date:
- Tue Mar 15 21:55:12 2016 +0000
- Parent:
- 0:43a77ff47221
- Commit message:
- Move interrupt work to main to avoid heavy workload in interrupt handler.
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 43a77ff47221 -r 69c43e344369 main.cpp --- a/main.cpp Mon Mar 14 02:30:27 2016 +0000 +++ b/main.cpp Tue Mar 15 21:55:12 2016 +0000 @@ -15,18 +15,21 @@ DigitalOut led1(LED1); InterruptIn userButton(USER_BUTTON); +bool buttonPressedInterrupt = false; +bool buttonReleasedInterrupt = false; + void buttonPressedCallback(void) { - led1 = BUTTON_PRESSED_LED_STATE; - DEBUG_0("button pressed\n"); + // Flag main to handle heavy work. Heavy work should not be handle in interrupt handler + buttonPressedInterrupt = true; } void buttonReleasedCallback(void) { - led1 = BUTTON_RELEASED_LED_STATE; - DEBUG_0("button released\n"); + // Flag main to handle heavy work. Heavy work should not be handle in interrupt handler + buttonReleasedInterrupt = true; } void @@ -44,10 +47,28 @@ main() { initBoard(); + + DEBUG_0("NUCLEO_BTN_LED_DEMO started\n"); + led1 = LED_ON; wait_ms(1000); led1 = LED_OFF; wait_ms(1000); while(1) { + if (buttonReleasedInterrupt) + { + led1 = BUTTON_RELEASED_LED_STATE; + DEBUG_0("button released\n"); + + buttonReleasedInterrupt = false; + } + + if (buttonPressedInterrupt) + { + led1 = BUTTON_PRESSED_LED_STATE; + DEBUG_0("button pressed\n"); + + buttonPressedInterrupt = false; + } } }