Skip to content

adding button debouncing example #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 17, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions examples/pybadger_button_debouncing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
from adafruit_debouncer import Debouncer
from adafruit_pybadger import pybadger

b_btn = Debouncer(lambda: pybadger.button.b == 0)
a_btn = Debouncer(lambda: pybadger.button.a == 0)
up_btn = Debouncer(lambda: pybadger.button.up == 0)
down_btn = Debouncer(lambda: pybadger.button.down == 0)
left_btn = Debouncer(lambda: pybadger.button.left == 0)
right_btn = Debouncer(lambda: pybadger.button.right == 0)

while True:
b_btn.update()
a_btn.update()
up_btn.update()
down_btn.update()
right_btn.update()
left_btn.update()

if b_btn.fell:
print("B pressed")
if b_btn.rose:
print("B released")

if a_btn.fell:
print("A pressed")
if a_btn.rose:
print("A released")

if up_btn.fell:
print("UP pressed")
if up_btn.rose:
print("UP released")

if down_btn.fell:
print("DOWN pressed")
if down_btn.rose:
print("DOWN released")

if right_btn.fell:
print("RIGHT pressed")
if right_btn.rose:
print("RIGHT released")

if left_btn.fell:
print("LEFT pressed")
if left_btn.rose:
print("LEFT released")