Created
May 22, 2017 14:30
-
-
Save mattvenn/1ca4dfad085c3331542450fbdee46525 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
samp = [1 ,1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1] | |
state = 1 | |
db0 = 0 | |
db1 = 0 | |
print("samp = button state 0 is pressed") | |
print("delta = samp ^ state difference between sample and state") | |
print("db0 = ~(db0) & delta first bit of 2 bit counter") | |
print("db1 = (db1 ^ db0) & delta second bit of 2 bit counter") | |
print("changes = ~(~delta | db0 | db1) if a change has happened") | |
print("state = state ^ changes state of the debouncer") | |
print("-----------") | |
print("{:5} {:5} {:5} {:5} {:5} {:5}".format("samp", "delta", "db0", "db1", "chngs", "state")) | |
for s in samp: | |
delta = s ^ state | |
db1 = (db1 ^ db0 ) & delta | |
db0 = ~(db0) & delta | |
changes = ~(~delta | db0 | db1) | |
state ^= changes | |
print("{:5} {:5} {:5} {:5} {:5} {:5}".format(s, delta, db0, db1, changes, state)) |
Author
mattvenn
commented
May 22, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment