Program to test sleep modes

Dependencies:   mbed-dev

Files at this revision

API Documentation at this revision

Comitter:
michaelVisimid
Date:
Tue Jan 31 21:35:49 2017 +0000
Commit message:
Program to test sleep modes

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-dev.lib Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r ac608f0bb1f5 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Jan 31 21:35:49 2017 +0000
@@ -0,0 +1,46 @@
+#include "mbed.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 + 1;
+    if (go_to_sleep > 3) go_to_sleep = 0;
+
+}
+
+int main()
+{
+    int i = 0;
+
+    printf("\nPress Button to enter/exit sleep & deepsleep\n");
+
+    event.fall(&pressed);
+
+    while (1) {
+
+        if ((go_to_sleep == 0) || (go_to_sleep == 2)) {
+            printf("%d: Running\n", i);
+            myled = !myled;
+            wait(1.0);
+        }
+
+        if (go_to_sleep == 1) {
+            myled = 0;
+            printf("%d: Entering sleep (press user button to resume)\n", i);
+            sleep();
+        }
+
+        if (go_to_sleep == 3) {
+            myled = 0;
+            printf("%d: Entering deepsleep (press user button to resume)\n", i);
+            deepsleep();
+        }
+
+        i++;
+    }
+}
diff -r 000000000000 -r ac608f0bb1f5 mbed-dev.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-dev.lib	Tue Jan 31 21:35:49 2017 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed-dev/#95d6b41a828b