VT4_DB

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 InterruptIn button(p30); // Interrupt on digital input p30
00003 DigitalOut led1(LED1); // digital out to onboard LED1
00004 Timer debounce; // define debounce timer
00005 LocalFileSystem local("local"); // define local file system
00006 void toggle(void); // function prototype
00007 int main()
00008 {
00009     debounce.start(); // start debounce timer
00010     button.rise(&toggle); // attach the toggle function to the rising edge
00011 }
00012 void toggle()   // perform toggle if debounce time has elapsed
00013 {
00014     if (debounce.read_ms()>200) {
00015         led1=!led1; // toggle LED
00016         FILE* Logfile = fopen ("/local/log.txt","a"); // open file for appending
00017         fprintf(Logfile,"time=%.3fs: setting led=%d\n\r",debounce.read(),led1.read());
00018         fclose(Logfile); // close file
00019         debounce.reset(); // reset debounce timer
00020     }
00021 }