Vjezba11_3

Dependencies:   mbed

Committer:
Goran002
Date:
Thu Nov 24 18:19:18 2016 +0000
Revision:
0:5117f0be3260
VT4_Herek Goran

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Goran002 0:5117f0be3260 1 #include "mbed.h"
Goran002 0:5117f0be3260 2 InterruptIn button(p30); // Interrupt on digital input p30
Goran002 0:5117f0be3260 3 DigitalOut led1(LED1); // digital out to onboard LED1
Goran002 0:5117f0be3260 4 Timer debounce; // define debounce timer
Goran002 0:5117f0be3260 5 LocalFileSystem local("local"); // define local file system
Goran002 0:5117f0be3260 6 void toggle(void); // function prototype
Goran002 0:5117f0be3260 7 int main()
Goran002 0:5117f0be3260 8 {
Goran002 0:5117f0be3260 9 debounce.start(); // start debounce timer
Goran002 0:5117f0be3260 10 button.rise(&toggle); // attach the toggle function to the rising edge
Goran002 0:5117f0be3260 11 }
Goran002 0:5117f0be3260 12 void toggle() // perform toggle if debounce time has elapsed
Goran002 0:5117f0be3260 13 {
Goran002 0:5117f0be3260 14 if (debounce.read_ms()>200) {
Goran002 0:5117f0be3260 15 led1=!led1; // toggle LED
Goran002 0:5117f0be3260 16 FILE* Logfile = fopen ("/local/log.txt","a"); // open file for appending
Goran002 0:5117f0be3260 17 fprintf(Logfile,"time=%.3fs: setting led=%d\n\r",debounce.read(),led1.read());
Goran002 0:5117f0be3260 18 fclose(Logfile); // close file
Goran002 0:5117f0be3260 19 debounce.reset(); // reset debounce timer
Goran002 0:5117f0be3260 20 }
Goran002 0:5117f0be3260 21 }