Toggle running with reset button. You can run and stop mbed without external switch. Push reset button to stop program. Push reset button to run program again. This sample program uses LocalFileSystem to save next running status.

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
Chi7Shi
Date:
Mon Nov 21 03:54:46 2011 +0000
Commit message:

Changed in this revision

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 9eb1ed79e0a3 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Nov 21 03:54:46 2011 +0000
@@ -0,0 +1,45 @@
+//
+// Toggle running with reset button  by K.Shibata
+// 
+// Push reset button to stop running.
+// Push reset button to run again. 
+//
+
+#include "mbed.h"
+
+DigitalOut myled(LED1);
+
+LocalFileSystem local( "local" );   // Create the local filesystem under the name "local"
+
+int main() {
+    FILE *fp;
+    bool is_checked = false;
+
+    fp = fopen( "/local/toggle.txt", "r" ); // Open "toggle.txt" on the local file system for reading.
+    if ( fp != NULL ) {
+        int c = fgetc( fp );
+        if ( c == '1' ) {
+            is_checked = true;
+        }
+        fclose( fp );
+    }
+
+    fp = fopen( "/local/toggle.txt", "w" ); // Open "toggle.txt" on the local file system for writing.
+    if ( fp != NULL ) {
+        if ( is_checked ) {
+            fputc( '0', fp );
+        } else {
+            fputc( '1', fp );
+        }
+        fclose( fp );
+    }
+
+    if ( is_checked ) while( 1 ); // Infinite loop.
+
+    while (1) {
+        myled = 1;
+        wait(0.2);
+        myled = 0;
+        wait(0.2);
+    }
+}
diff -r 000000000000 -r 9eb1ed79e0a3 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Mon Nov 21 03:54:46 2011 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/63bcd7ba4912