Last active
July 25, 2022 21:01
-
-
Save plasticrake/60137e7ac8fe89f6cb55f8e676c3f679 to your computer and use it in GitHub Desktop.
arcade
This file contains 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
from time import monotonic_ns | |
from adafruit_seesaw.digitalio import DigitalIO | |
from adafruit_seesaw.pwmout import PWMOut | |
from adafruit_seesaw.seesaw import Seesaw | |
class ArcadeButton: | |
def __init__(self, seesaw: Seesaw, button_pin: int, led_pin: int): | |
self.button = DigitalIO(seesaw, button_pin) | |
seesaw.pin_mode(button_pin, seesaw.INPUT_PULLUP) | |
self.led = PWMOut(seesaw, led_pin) | |
def monitor(self): | |
if not self.button.value: | |
print(f"pressed {monotonic_ns() / 1_000_000}ms") | |
def init_arcade(seesaw: Seesaw): | |
arcade_buttons: list[ArcadeButton] = [] | |
button_led_pins = ((18, 12), (19, 12), (20, 0), (2, 1)) | |
for (button_pin, led_pin) in button_led_pins: | |
arcade_button = ArcadeButton(seesaw, button_pin, led_pin) | |
arcade_buttons.append(arcade_button) | |
return arcade_buttons |
This file contains 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
import board | |
import busio | |
from adafruit_seesaw.seesaw import Seesaw | |
from arcade import init_arcade | |
i2c = busio.I2C(board.SCL, board.SDA, frequency=400_000) | |
arcade_buttons = init_arcade(Seesaw(i2c, 0x3A)) + init_arcade(Seesaw(i2c, 0x3B)) | |
while True: | |
for arcade_button in arcade_buttons: | |
arcade_button.monitor() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment