Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
00001 /* Program Example 10.3: Interrupt toggle switch with formatted data logging to text file 00002 */ 00003 00004 #include "mbed.h" 00005 00006 InterruptIn button(p30); // Interrupt on digital input 20 00007 DigitalOut led1(LED1); // digital out to onboard LED1 00008 Timer debounce; // define debounce timer 00009 LocalFileSystem local("local"); // define local file system 00010 00011 void toggle(void); // function prototype 00012 00013 int main() { 00014 debounce.start(); 00015 button.rise(&toggle); // attach the address of the toggle function to the rising edge 00016 } 00017 00018 void toggle() { 00019 if (debounce.read_ms()>200) 00020 led1=!led1; 00021 FILE* Logfile = fopen ("/local/log.txt","a"); // open file for reading 00022 fprintf(Logfile,"time=%.3fs: button pressed so setting led=%d\n\r",debounce.read(),led1.read()); 00023 fclose(Logfile); 00024 debounce.reset(); 00025 }
Generated on Thu Jul 14 2022 11:42:43 by
1.7.2