test gpio buttons

This commit is contained in:
ohsqueezy 2022-12-16 11:11:56 -05:00
parent ced7540262
commit d62f8876e5
2 changed files with 8 additions and 5 deletions

View File

@ -27,8 +27,8 @@ except ImportError:
class ElectricSieve(Game):
# The GPIO pins corresponding to the buttons and LED indicators
PIN_BUTTON_UP = 17
PIN_BUTTON_DOWN = 27
PIN_BUTTON_LEFT = 17
PIN_BUTTON_RIGHT = 27
PIN_LED_UP = 22
PIN_LED_DOWN = 23
@ -80,7 +80,7 @@ class ElectricSieve(Game):
GPIO.setmode(GPIO.BCM)
# Set button pins to pullup and attach to each a callback that runs on press or release
for pin in self.PIN_BUTTON_UP, self.PIN_BUTTON_DOWN:
for pin in self.PIN_BUTTON_LEFT, self.PIN_BUTTON_RIGHT:
GPIO.setup(pin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.add_event_detect(pin, GPIO.BOTH, self.gpio_input)
@ -93,9 +93,11 @@ class ElectricSieve(Game):
@param pin Raspberry Pi pin number as read by the RPi.GPIO library
"""
cancel = not (GPIO.input(pin) == GPIO.LOW)
if pin == ElectricSieve.PIN_BUTTON_UP:
if pin == ElectricSieve.PIN_BUTTON_LEFT:
print("left")
self.input.post_command("left", cancel=cancel)
elif pin == ElectricSieve.PIN_BUTTON_DOWN:
elif pin == ElectricSieve.PIN_BUTTON_RIGHT:
print("right")
self.input.post_command("right", cancel=cancel)
self.input.post_any_command(id=pin, cancel=cancel)

View File

@ -144,3 +144,4 @@
1671086208.2518148 135 ---
1671161829.4724848 14 ---
1671168164.8205705 0 ---
1671206866.9558506 39 ---