Skip to content

Commit

Permalink
Merge pull request #117 from kattni/add-gamepad-qt
Browse files Browse the repository at this point in the history
Add Gamepad QT compatibility, example.
  • Loading branch information
kattni authored Jun 26, 2023
2 parents 5d01265 + ebc0198 commit d99b564
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 1 deletion.
3 changes: 2 additions & 1 deletion adafruit_seesaw/seesaw.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
65 changes: 65 additions & 0 deletions examples/seesaw_gamepad_qt.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit d99b564

Please sign in to comment.