Helmut Tschemernjak
/
Nucleo_blink_led_deepsleep
I little test which wakes up from deepsleep via user buttom click and turns on the LED.
main.cpp@0:3208dcf3974f, 2016-09-22 (annotated)
- Committer:
- Helmut64
- Date:
- Thu Sep 22 13:05:35 2016 +0000
- Revision:
- 0:3208dcf3974f
Updated test deepsleep;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Helmut64 | 0:3208dcf3974f | 1 | #include "mbed.h" |
Helmut64 | 0:3208dcf3974f | 2 | |
Helmut64 | 0:3208dcf3974f | 3 | DigitalOut myled(LED1); |
Helmut64 | 0:3208dcf3974f | 4 | InterruptIn event(USER_BUTTON); |
Helmut64 | 0:3208dcf3974f | 5 | |
Helmut64 | 0:3208dcf3974f | 6 | Serial ser(USBTX, USBRX); |
Helmut64 | 0:3208dcf3974f | 7 | |
Helmut64 | 0:3208dcf3974f | 8 | bool pressed = false; |
Helmut64 | 0:3208dcf3974f | 9 | |
Helmut64 | 0:3208dcf3974f | 10 | void KeyPressed() |
Helmut64 | 0:3208dcf3974f | 11 | { |
Helmut64 | 0:3208dcf3974f | 12 | ser.printf("Key Pressed\r\n"); |
Helmut64 | 0:3208dcf3974f | 13 | pressed = true; |
Helmut64 | 0:3208dcf3974f | 14 | } |
Helmut64 | 0:3208dcf3974f | 15 | |
Helmut64 | 0:3208dcf3974f | 16 | int main() { |
Helmut64 | 0:3208dcf3974f | 17 | ser.baud(230400); |
Helmut64 | 0:3208dcf3974f | 18 | ser.printf("Hello, World\r\n"); |
Helmut64 | 0:3208dcf3974f | 19 | event.fall(&KeyPressed); |
Helmut64 | 0:3208dcf3974f | 20 | |
Helmut64 | 0:3208dcf3974f | 21 | while(1) { |
Helmut64 | 0:3208dcf3974f | 22 | myled = 1; |
Helmut64 | 0:3208dcf3974f | 23 | wait(0.2); |
Helmut64 | 0:3208dcf3974f | 24 | myled = 0; |
Helmut64 | 0:3208dcf3974f | 25 | wait(1.0); |
Helmut64 | 0:3208dcf3974f | 26 | if (pressed) { |
Helmut64 | 0:3208dcf3974f | 27 | deepsleep(); |
Helmut64 | 0:3208dcf3974f | 28 | pressed = false; |
Helmut64 | 0:3208dcf3974f | 29 | } |
Helmut64 | 0:3208dcf3974f | 30 | } |
Helmut64 | 0:3208dcf3974f | 31 | } |