Advertisement
Guest User

Untitled

a guest
May 22nd, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. 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]
  2. state = 1
  3. db0 = 0
  4. db1 = 0
  5. print("samp = button state 0 is pressed")
  6. print("delta = samp ^ state difference between sample and state")
  7. print("db0 = ~(db0) & delta first bit of 2 bit counter")
  8. print("db1 = (db1 ^ db0) & delta second bit of 2 bit counter")
  9. print("changes = ~(~delta | db0 | db1) if a change has happened")
  10. print("state = state ^ changes state of the debouncer")
  11. print("-----------")
  12. print("{:5} {:5} {:5} {:5} {:5} {:5}".format("samp", "delta", "db0", "db1", "chngs", "state"))
  13. for s in samp:
  14. delta = s ^ state
  15. db1 = (db1 ^ db0 ) & delta
  16. db0 = ~(db0) & delta
  17. changes = ~(~delta | db0 | db1)
  18. state ^= changes
  19. print("{:5} {:5} {:5} {:5} {:5} {:5}".format(s, delta, db0, db1, changes, state))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement