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.
Diff: main.cpp
- Revision:
- 0:9eb1ed79e0a3
--- /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); + } +}