Software Switch Debouncing

How can we easily debounce those pesky mechanical switches without using external components and without tying up processor cycles in a wait loop?
The answer is easy. We can use a virtual shift register. The I/O pin the switch is connected to is sampled at periodic intervals and its logic level at that instant is shifted into a virtual shift register. Once all bits of the shift register are 0 or 1, the switch is considered to have settled into an on or off state, respectively.

The flow diagram to debounce the switches (code omitted to keep it architecture-independent):

Debounce.png

The flow diagram and code to process the output of the debouncing function:

Debouncing.png

Sort:  

Hello! Your post has been resteemed and upvoted by @ilovecoding because we love coding! Keep up good work! Consider upvoting this comment to support the @ilovecoding and increase your future rewards! ^_^ Steem On!

Reply !stop to disable the comment. Thanks!

Coin Marketplace

STEEM 0.24
TRX 0.11
JST 0.031
BTC 61388.48
ETH 2984.48
USDT 1.00
SBD 3.65