ss

Dependencies:   mbed-stm32l0/l1-src

Fork of Nucleo_sleep by ST

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 
00003 InterruptIn event(PC_13);
00004 DigitalOut myled(PB_3);
00005 Serial pc(PB_6, PB_7);
00006 DigitalOut VccEnable(PB_5);
00007 int go_to_sleep = 0;
00008 
00009 void pressed()
00010 {
00011     pc.printf("Button pressed\n");
00012     go_to_sleep = go_to_sleep + 1;
00013     if (go_to_sleep > 3) go_to_sleep = 0;
00014 
00015 }
00016 
00017 int main()
00018 {
00019     int i = 0;
00020     VccEnable = 0;   //功能电源开关,0:on,1:off
00021     pc.printf("\nPress Button to enter/exit sleep & deepsleep\n");
00022   //  VccEnable = 0;
00023 
00024     event.fall(&pressed);
00025 
00026     while (1) {
00027 
00028         if ((go_to_sleep == 0) || (go_to_sleep == 2)) {
00029             pc.printf("%d: Running\n", i);
00030             myled = !myled;
00031             wait(1.0);
00032         }
00033 
00034         if (go_to_sleep == 1) {
00035             myled = 0;
00036             pc.printf("%d: Entering sleep (press user button to resume)\n", i);
00037             sleep();
00038         }
00039 
00040         if (go_to_sleep == 2) {
00041             myled = 0;
00042             pc.printf("%d: Entering deepsleep (press user button to resume)\n", i);
00043             deepsleep();
00044         }
00045 
00046         i++;
00047     }
00048 }