diff --git a/adafruit_seesaw/seesaw.py b/adafruit_seesaw/seesaw.py index bbd3884..91a1512 100644 --- a/adafruit_seesaw/seesaw.py +++ b/adafruit_seesaw/seesaw.py @@ -119,6 +119,7 @@ def const(x): _ROBOHATMM1_PID = const(9998) _5690_PID = const(5690) _5681_PID = const(5681) +_5743_PID = const(5743) class Seesaw: @@ -163,7 +164,7 @@ def __init__(self, i2c_bus, addr=0x49, drdy=None, reset=True): from adafruit_seesaw.robohat import MM1_Pinmap self.pin_mapping = MM1_Pinmap - elif pid in (_5690_PID, _5681_PID): + elif pid in (_5690_PID, _5681_PID, _5743_PID): from adafruit_seesaw.attinyx16 import ATtinyx16_Pinmap self.pin_mapping = ATtinyx16_Pinmap diff --git a/examples/seesaw_gamepad_qt.py b/examples/seesaw_gamepad_qt.py new file mode 100644 index 0000000..b6ed18b --- /dev/null +++ b/examples/seesaw_gamepad_qt.py @@ -0,0 +1,65 @@ +# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# SPDX-FileCopyrightText: 2023 Kattni Rembor for Adafruit Industries + +# SPDX-License-Identifier: MIT + +import time +import board +from micropython import const +from adafruit_seesaw.seesaw import Seesaw + +BUTTON_X = const(6) +BUTTON_Y = const(2) +BUTTON_A = const(5) +BUTTON_B = const(1) +BUTTON_SELECT = const(0) +BUTTON_START = const(16) +button_mask = const( + (1 << BUTTON_X) + | (1 << BUTTON_Y) + | (1 << BUTTON_A) + | (1 << BUTTON_B) + | (1 << BUTTON_SELECT) + | (1 << BUTTON_START) +) + +i2c_bus = board.STEMMA_I2C() # The built-in STEMMA QT connector on the microcontroller +# i2c_bus = board.I2C() # Uses board.SCL and board.SDA. Use with breadboard. + +seesaw = Seesaw(i2c_bus, addr=0x50) + +seesaw.pin_mode_bulk(button_mask, seesaw.INPUT_PULLUP) + +last_x = 0 +last_y = 0 + +while True: + x = 1023 - seesaw.analog_read(14) + y = 1023 - seesaw.analog_read(15) + + if (abs(x - last_x) > 3) or (abs(y - last_y) > 3): + print(x, y) + last_x = x + last_y = y + + buttons = seesaw.digital_read_bulk(button_mask) + + if not buttons & (1 << BUTTON_X): + print("Button x pressed") + + if not buttons & (1 << BUTTON_Y): + print("Button Y pressed") + + if not buttons & (1 << BUTTON_A): + print("Button A pressed") + + if not buttons & (1 << BUTTON_B): + print("Button B pressed") + + if not buttons & (1 << BUTTON_SELECT): + print("Button Select pressed") + + if not buttons & (1 << BUTTON_START): + print("Button Start pressed") + + time.sleep(0.01)