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.