Control de rebotes.

Dependencies:   mbed

Committer:
jangelgm
Date:
Thu Mar 09 21:49:01 2017 +0000
Revision:
0:44c7fcb872d1
Control de rebotes.

Who changed what in which revision?

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