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.
Dependencies: mbed
Diff: main.cpp
- Revision:
- 0:2e568740b2dd
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Thu Nov 24 18:18:48 2016 +0000
@@ -0,0 +1,19 @@
+#include "mbed.h"
+InterruptIn button(p30); // Interrupt on digital input p30
+DigitalOut led1(LED1); // digital out to onboard LED1
+Timer debounce; // define debounce timer
+LocalFileSystem local("local"); // define local file system
+void toggle(void); // function prototype
+int main() {
+debounce.start(); // start debounce timer
+button.rise(&toggle); // attach the toggle function to the rising edge
+}
+void toggle() { // perform toggle if debounce time has elapsed
+if (debounce.read_ms()>200) {
+led1=!led1; // toggle LED
+FILE* Logfile = fopen ("/local/log.txt","a"); // open file for appending
+fprintf(Logfile,"time=%.3fs: setting led=%d\n\r",debounce.read(),led1.read());
+fclose(Logfile); // close file
+debounce.reset(); // reset debounce timer
+}
+}
\ No newline at end of file