Enter in sleep or deepsleep modes.

Dependencies:   mbed

Fork of Nucleo_sleep by ST

Committer:
bcostm
Date:
Fri Feb 21 10:27:35 2014 +0000
Revision:
0:69ffa4abe5b6
Initial version.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bcostm 0:69ffa4abe5b6 1 #include "mbed.h"
bcostm 0:69ffa4abe5b6 2
bcostm 0:69ffa4abe5b6 3 InterruptIn event(USER_BUTTON);
bcostm 0:69ffa4abe5b6 4 DigitalOut myled(LED1);
bcostm 0:69ffa4abe5b6 5
bcostm 0:69ffa4abe5b6 6 int go_to_sleep = 0;
bcostm 0:69ffa4abe5b6 7
bcostm 0:69ffa4abe5b6 8 void pressed()
bcostm 0:69ffa4abe5b6 9 {
bcostm 0:69ffa4abe5b6 10 printf("Button pressed\n");
bcostm 0:69ffa4abe5b6 11 go_to_sleep = !go_to_sleep;
bcostm 0:69ffa4abe5b6 12 }
bcostm 0:69ffa4abe5b6 13
bcostm 0:69ffa4abe5b6 14 int main()
bcostm 0:69ffa4abe5b6 15 {
bcostm 0:69ffa4abe5b6 16 int i = 0;
bcostm 0:69ffa4abe5b6 17
bcostm 0:69ffa4abe5b6 18 event.fall(&pressed);
bcostm 0:69ffa4abe5b6 19
bcostm 0:69ffa4abe5b6 20 while (1) {
bcostm 0:69ffa4abe5b6 21 if (go_to_sleep) {
bcostm 0:69ffa4abe5b6 22 myled = 1;
bcostm 0:69ffa4abe5b6 23 printf("%d: Entering sleep (press user button to resume)\n", i);
bcostm 0:69ffa4abe5b6 24 sleep();
bcostm 0:69ffa4abe5b6 25 //deepsleep();
bcostm 0:69ffa4abe5b6 26 //wait(0.1);
bcostm 0:69ffa4abe5b6 27 } else {
bcostm 0:69ffa4abe5b6 28 printf("%d: Running\n", i);
bcostm 0:69ffa4abe5b6 29 myled = !myled;
bcostm 0:69ffa4abe5b6 30 wait(1.0);
bcostm 0:69ffa4abe5b6 31 }
bcostm 0:69ffa4abe5b6 32 i++;
bcostm 0:69ffa4abe5b6 33 }
bcostm 0:69ffa4abe5b6 34 }