VT4_Borko Jurac
Dependencies: mbed
main.cpp@0:2e568740b2dd, 2016-11-24 (annotated)
- Committer:
- Borko
- Date:
- Thu Nov 24 18:18:48 2016 +0000
- Revision:
- 0:2e568740b2dd
VT4_Borko Jurac
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Borko | 0:2e568740b2dd | 1 | #include "mbed.h" |
Borko | 0:2e568740b2dd | 2 | InterruptIn button(p30); // Interrupt on digital input p30 |
Borko | 0:2e568740b2dd | 3 | DigitalOut led1(LED1); // digital out to onboard LED1 |
Borko | 0:2e568740b2dd | 4 | Timer debounce; // define debounce timer |
Borko | 0:2e568740b2dd | 5 | LocalFileSystem local("local"); // define local file system |
Borko | 0:2e568740b2dd | 6 | void toggle(void); // function prototype |
Borko | 0:2e568740b2dd | 7 | int main() { |
Borko | 0:2e568740b2dd | 8 | debounce.start(); // start debounce timer |
Borko | 0:2e568740b2dd | 9 | button.rise(&toggle); // attach the toggle function to the rising edge |
Borko | 0:2e568740b2dd | 10 | } |
Borko | 0:2e568740b2dd | 11 | void toggle() { // perform toggle if debounce time has elapsed |
Borko | 0:2e568740b2dd | 12 | if (debounce.read_ms()>200) { |
Borko | 0:2e568740b2dd | 13 | led1=!led1; // toggle LED |
Borko | 0:2e568740b2dd | 14 | FILE* Logfile = fopen ("/local/log.txt","a"); // open file for appending |
Borko | 0:2e568740b2dd | 15 | fprintf(Logfile,"time=%.3fs: setting led=%d\n\r",debounce.read(),led1.read()); |
Borko | 0:2e568740b2dd | 16 | fclose(Logfile); // close file |
Borko | 0:2e568740b2dd | 17 | debounce.reset(); // reset debounce timer |
Borko | 0:2e568740b2dd | 18 | } |
Borko | 0:2e568740b2dd | 19 | } |