Jose Rios
/
Nucleo_Sleep
A sleep (or deepSleep) example with button interrupt wakeup
Revision 0:4d80b159d444, committed 2014-09-08
- Comitter:
- jose_23991
- Date:
- Mon Sep 08 17:41:39 2014 +0000
- Commit message:
- Version 1.0
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r 4d80b159d444 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Mon Sep 08 17:41:39 2014 +0000 @@ -0,0 +1,38 @@ +#include "mbed.h" + +InterruptIn event_button(USER_BUTTON); // Create the button event object +volatile bool go_to_sleep = false; // Volatile variable to make the system sleep + +void ISR_pressed() // ISR for the button press +{ + printf("Button pressed\n"); // Show that the button has pressed + go_to_sleep = !go_to_sleep; // Toogle the sleep state + event_button.disable_irq(); // Disable the interrupt request +} + +int main() +{ + int i = 0; + + event_button.mode(PullUp); // Setup the internall pull-up resistor + event_button.fall(&ISR_pressed); // Set the ISR associated to event fall (push the button) + + while(1) + { + if(go_to_sleep) + { + printf("%d: Entering sleep (press user button to resume)\n", i); + + event_button.enable_irq(); // Enable the interrupt request + //sleep(); // Enter Low Power Mode + deepsleep(); // Enter Low Power Mode (deep) + wait_ms(200); // Wait 200ms for debounce + event_button.enable_irq(); // Enable the interrupt request + } + else + { + printf("%d: Running\n", i); // Show the counter + } + i++; + } +}
diff -r 000000000000 -r 4d80b159d444 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Mon Sep 08 17:41:39 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/9327015d4013 \ No newline at end of file