C program to debounce an input pin Because many microcontrollers operate in nois
ID: 3551662 • Letter: C
Question
C program to debounce an input pin
Because many microcontrollers operate in noisy environments, the first detection of a signal-transition cannot always be trusted (i.e., it might be a glitch on the line). Additionally, many mechanical switches are notorious for bouncing when they are first pressed or released. So, you are to write a function that debounces an input pin. Your function should be called whenever the first signal-event occurs on an input pin, and it should debounce for a reasonable amount of time (e.g., 20 msec). At the end of the debounce time, the input should be re-sampled and compared to the original state of the line; if they are different, you should declare that a valid transition has occurred.Explanation / Answer
#define DEBOUNCE 20 buttons[] = {14, 15, 16, 17, 18, 19}; #define NUMBUTTONS sizeof(buttons) pressed[NUMBUTTONS], justpressed[NUMBUTTONS], justreleased[NUMBUTTONS]; () { i; .(9600); .(); .(NUMBUTTONS, ); .(); (13, ); (i=0; iRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.