new one sleep / deepsleep and timer wakeup sample code

Dependencies:   WakeUp mbed

Files at this revision

API Documentation at this revision

Comitter:
joshchen
Date:
Thu Nov 27 03:12:02 2014 +0000
Commit message:
leverage https://developer.mbed.org/users/Sissors/code/WakeUp/; and original sleep sample code to make new one

Changed in this revision

WakeUp.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 53ff53c686e1 WakeUp.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/WakeUp.lib	Thu Nov 27 03:12:02 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/Sissors/code/WakeUp/#f3adba7cf7c4
diff -r 000000000000 -r 53ff53c686e1 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Nov 27 03:12:02 2014 +0000
@@ -0,0 +1,59 @@
+#include "mbed.h"
+#include "WakeUp.h"
+
+InterruptIn event(USER_BUTTON);
+DigitalOut myled(LED1);
+
+int go_to_sleep = 0;
+ 
+void pressed()
+{
+    printf("Button pressed\n");
+    go_to_sleep = !go_to_sleep;
+}
+
+void gotoSleep(int seconds)
+{
+    //Set wakeup time for seconds
+    int s=seconds*1000;
+    WakeUp::set_ms(s);
+    
+    printf("==> Entering deepsleep until %d seconds\n", seconds);
+    //Enter deepsleep, the program won't go beyond this point until it is woken up
+    deepsleep();
+    wait(0.1);
+}
+
+void sleepUtilPressed()
+{
+    printf("==> Entering deepsleep (press user button to resume)\n");
+    //sleep();
+    deepsleep();
+    wait(0.1);
+}
+ 
+int main()
+{
+    int i = 0;
+    
+    wait(5);
+    //The low-power oscillator can be quite inaccurate on some targets
+    //this function calibrates it against the main clock
+    WakeUp::calibrate();
+    
+    event.fall(&pressed);
+ 
+    while (1) {
+        if (go_to_sleep) {
+            myled = 0;
+            gotoSleep(2);
+            //sleepUtilPressed();
+            go_to_sleep=0;
+        } else {
+            printf("%d: Running\n", i);
+            myled = !myled;
+            wait(1.0);
+        }
+        i++;
+    }
+}
diff -r 000000000000 -r 53ff53c686e1 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Nov 27 03:12:02 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/031413cf7a89
\ No newline at end of file