Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
main.cpp@0:8e1b0b607dc3, 2015-12-01 (annotated)
- Committer:
- iFoxtec
- Date:
- Tue Dec 01 15:45:13 2015 +0000
- Revision:
- 0:8e1b0b607dc3
- Child:
- 1:053449444c29
1st
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
iFoxtec | 0:8e1b0b607dc3 | 1 | #include "mbed.h" |
iFoxtec | 0:8e1b0b607dc3 | 2 | |
iFoxtec | 0:8e1b0b607dc3 | 3 | InterruptIn event(USER_BUTTON); |
iFoxtec | 0:8e1b0b607dc3 | 4 | DigitalOut myled(LED1); |
iFoxtec | 0:8e1b0b607dc3 | 5 | |
iFoxtec | 0:8e1b0b607dc3 | 6 | int go_to_sleep = 0; |
iFoxtec | 0:8e1b0b607dc3 | 7 | |
iFoxtec | 0:8e1b0b607dc3 | 8 | void pressed() |
iFoxtec | 0:8e1b0b607dc3 | 9 | { |
iFoxtec | 0:8e1b0b607dc3 | 10 | printf("Button pressed\n"); |
iFoxtec | 0:8e1b0b607dc3 | 11 | go_to_sleep = !go_to_sleep; |
iFoxtec | 0:8e1b0b607dc3 | 12 | } |
iFoxtec | 0:8e1b0b607dc3 | 13 | |
iFoxtec | 0:8e1b0b607dc3 | 14 | int main() |
iFoxtec | 0:8e1b0b607dc3 | 15 | { |
iFoxtec | 0:8e1b0b607dc3 | 16 | |
iFoxtec | 0:8e1b0b607dc3 | 17 | HAL_PWR_EnableWakeUpPin(USER_BUTTON); |
iFoxtec | 0:8e1b0b607dc3 | 18 | int i = 0; |
iFoxtec | 0:8e1b0b607dc3 | 19 | |
iFoxtec | 0:8e1b0b607dc3 | 20 | //event.fall(&pressed); |
iFoxtec | 0:8e1b0b607dc3 | 21 | |
iFoxtec | 0:8e1b0b607dc3 | 22 | while (1) { |
iFoxtec | 0:8e1b0b607dc3 | 23 | event.fall(&pressed); |
iFoxtec | 0:8e1b0b607dc3 | 24 | if (go_to_sleep) { |
iFoxtec | 0:8e1b0b607dc3 | 25 | //myled = 1; |
iFoxtec | 0:8e1b0b607dc3 | 26 | printf("%d: Entering sleep (press user button to resume)\n", i); |
iFoxtec | 0:8e1b0b607dc3 | 27 | //sleep(); |
iFoxtec | 0:8e1b0b607dc3 | 28 | //deepsleep(); |
iFoxtec | 0:8e1b0b607dc3 | 29 | HAL_PWR_EnterSTOPMode(PWR_MAINREGULATOR_ON, PWR_STOPENTRY_WFI); |
iFoxtec | 0:8e1b0b607dc3 | 30 | |
iFoxtec | 0:8e1b0b607dc3 | 31 | //wait(0.1); |
iFoxtec | 0:8e1b0b607dc3 | 32 | } else { |
iFoxtec | 0:8e1b0b607dc3 | 33 | printf("%d: Running\n", i); |
iFoxtec | 0:8e1b0b607dc3 | 34 | myled = !myled; |
iFoxtec | 0:8e1b0b607dc3 | 35 | wait(1.0); |
iFoxtec | 0:8e1b0b607dc3 | 36 | } |
iFoxtec | 0:8e1b0b607dc3 | 37 | i++; |
iFoxtec | 0:8e1b0b607dc3 | 38 | } |
iFoxtec | 0:8e1b0b607dc3 | 39 | } |