Esercitazione5_10

Dependencies:   mbed

Committer:
MDevolution
Date:
Mon Oct 31 11:17:57 2016 +0000
Revision:
0:b765c25dc19d
Esercitazione5_10

Who changed what in which revision?

UserRevisionLine numberNew contents of line
MDevolution 0:b765c25dc19d 1 /* Program Example 10: Event driven LED switching with switch debounce
MDevolution 0:b765c25dc19d 2 */
MDevolution 0:b765c25dc19d 3 #include "mbed.h"
MDevolution 0:b765c25dc19d 4 InterruptIn button(PC_13); // Interrupt on digital pushbutton input p18
MDevolution 0:b765c25dc19d 5 DigitalOut led1(LED1); // digital out to LED1
MDevolution 0:b765c25dc19d 6 Timer debounce; // define debounce timer
MDevolution 0:b765c25dc19d 7 void toggle(void); // function prototype
MDevolution 0:b765c25dc19d 8
MDevolution 0:b765c25dc19d 9 int main(){
MDevolution 0:b765c25dc19d 10 debounce.start();
MDevolution 0:b765c25dc19d 11 button.rise(&toggle); // attach the address of the toggle
MDevolution 0:b765c25dc19d 12 }
MDevolution 0:b765c25dc19d 13
MDevolution 0:b765c25dc19d 14 // function to the rising edge
MDevolution 0:b765c25dc19d 15 void toggle()
MDevolution 0:b765c25dc19d 16 {
MDevolution 0:b765c25dc19d 17 if (debounce.read_ms()>10) // only allow toggle if debounce timer
MDevolution 0:b765c25dc19d 18 led1=!led1; // has passed 10 ms
MDevolution 0:b765c25dc19d 19 debounce.reset(); // restart timer when the toggle is performed
MDevolution 0:b765c25dc19d 20 }