ss

Dependencies:   mbed-stm32l0/l1-src

Fork of Nucleo_sleep by ST

Committer:
bcostm
Date:
Wed Jan 27 14:50:17 2016 +0000
Revision:
1:58b6efe82b46
Parent:
0:69ffa4abe5b6
Child:
2:09cd5f5c566f
Add sleep and deepsleep in the same example.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bcostm 0:69ffa4abe5b6 1 #include "mbed.h"
bcostm 1:58b6efe82b46 2
bcostm 0:69ffa4abe5b6 3 InterruptIn event(USER_BUTTON);
bcostm 0:69ffa4abe5b6 4 DigitalOut myled(LED1);
bcostm 1:58b6efe82b46 5 Serial pc(SERIAL_TX, SERIAL_RX);
bcostm 1:58b6efe82b46 6
bcostm 0:69ffa4abe5b6 7 int go_to_sleep = 0;
bcostm 1:58b6efe82b46 8
bcostm 0:69ffa4abe5b6 9 void pressed()
bcostm 0:69ffa4abe5b6 10 {
bcostm 1:58b6efe82b46 11 pc.printf("Button pressed\n");
bcostm 1:58b6efe82b46 12 go_to_sleep = go_to_sleep + 1;
bcostm 1:58b6efe82b46 13 if (go_to_sleep > 3) go_to_sleep = 0;
bcostm 1:58b6efe82b46 14
bcostm 0:69ffa4abe5b6 15 }
bcostm 1:58b6efe82b46 16
bcostm 0:69ffa4abe5b6 17 int main()
bcostm 0:69ffa4abe5b6 18 {
bcostm 0:69ffa4abe5b6 19 int i = 0;
bcostm 1:58b6efe82b46 20
bcostm 1:58b6efe82b46 21 pc.printf("\nPress Button to enter/exit sleep & deepsleep\n");
bcostm 1:58b6efe82b46 22
bcostm 0:69ffa4abe5b6 23 event.fall(&pressed);
bcostm 1:58b6efe82b46 24
bcostm 0:69ffa4abe5b6 25 while (1) {
bcostm 1:58b6efe82b46 26
bcostm 1:58b6efe82b46 27 if ((go_to_sleep == 0) || (go_to_sleep == 2)) {
bcostm 1:58b6efe82b46 28 pc.printf("%d: Running\n", i);
bcostm 0:69ffa4abe5b6 29 myled = !myled;
bcostm 0:69ffa4abe5b6 30 wait(1.0);
bcostm 0:69ffa4abe5b6 31 }
bcostm 1:58b6efe82b46 32
bcostm 1:58b6efe82b46 33 if (go_to_sleep == 1) {
bcostm 1:58b6efe82b46 34 myled = 0;
bcostm 1:58b6efe82b46 35 pc.printf("%d: Entering sleep (press user button to resume)\n", i);
bcostm 1:58b6efe82b46 36 sleep();
bcostm 1:58b6efe82b46 37 }
bcostm 1:58b6efe82b46 38
bcostm 1:58b6efe82b46 39 if (go_to_sleep == 3) {
bcostm 1:58b6efe82b46 40 myled = 0;
bcostm 1:58b6efe82b46 41 pc.printf("%d: Entering deepsleep (press user button to resume)\n", i);
bcostm 1:58b6efe82b46 42 deepsleep();
bcostm 1:58b6efe82b46 43 }
bcostm 1:58b6efe82b46 44
bcostm 0:69ffa4abe5b6 45 i++;
bcostm 0:69ffa4abe5b6 46 }
bcostm 0:69ffa4abe5b6 47 }