Quote:
Originally Posted by Ether
As shown, it debounces only in one direction: it requires 5 ones in a row to switch the output to 1, but only one zero to switch back to zero (and stay zero until 5 more consecutive ones are seen).
If you want to debounce in both directions, change the second line to
Code:
if(output==0) output=truncate(ave+0.03); else output=truncate(ave+1-0.03);
|
If I understand what you're doing, .03 is a nice way to represent 2 ^ -5, and if you wanted more or less consecutive bits (allowing longer debouncing) you'd adjust the exponent accordingly.
__________________

Be Healthy. Never Stop Learning. Say It Like It Is. Own It. Like our values?
Flexware Innovation is hiring!. We're looking for Senior Automation, Software, and System Engineers.
Check us out!