Skip to content

Commit d99b564

Browse files
authored
Merge pull request #117 from kattni/add-gamepad-qt
Add Gamepad QT compatibility, example.
2 parents 5d01265 + ebc0198 commit d99b564

File tree

2 files changed

+67
-1
lines changed

2 files changed

+67
-1
lines changed

adafruit_seesaw/seesaw.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ def const(x):
119119
_ROBOHATMM1_PID = const(9998)
120120
_5690_PID = const(5690)
121121
_5681_PID = const(5681)
122+
_5743_PID = const(5743)
122123

123124

124125
class Seesaw:
@@ -163,7 +164,7 @@ def __init__(self, i2c_bus, addr=0x49, drdy=None, reset=True):
163164
from adafruit_seesaw.robohat import MM1_Pinmap
164165

165166
self.pin_mapping = MM1_Pinmap
166-
elif pid in (_5690_PID, _5681_PID):
167+
elif pid in (_5690_PID, _5681_PID, _5743_PID):
167168
from adafruit_seesaw.attinyx16 import ATtinyx16_Pinmap
168169

169170
self.pin_mapping = ATtinyx16_Pinmap

examples/seesaw_gamepad_qt.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
2+
# SPDX-FileCopyrightText: 2023 Kattni Rembor for Adafruit Industries
3+
4+
# SPDX-License-Identifier: MIT
5+
6+
import time
7+
import board
8+
from micropython import const
9+
from adafruit_seesaw.seesaw import Seesaw
10+
11+
BUTTON_X = const(6)
12+
BUTTON_Y = const(2)
13+
BUTTON_A = const(5)
14+
BUTTON_B = const(1)
15+
BUTTON_SELECT = const(0)
16+
BUTTON_START = const(16)
17+
button_mask = const(
18+
(1 << BUTTON_X)
19+
| (1 << BUTTON_Y)
20+
| (1 << BUTTON_A)
21+
| (1 << BUTTON_B)
22+
| (1 << BUTTON_SELECT)
23+
| (1 << BUTTON_START)
24+
)
25+
26+
i2c_bus = board.STEMMA_I2C() # The built-in STEMMA QT connector on the microcontroller
27+
# i2c_bus = board.I2C() # Uses board.SCL and board.SDA. Use with breadboard.
28+
29+
seesaw = Seesaw(i2c_bus, addr=0x50)
30+
31+
seesaw.pin_mode_bulk(button_mask, seesaw.INPUT_PULLUP)
32+
33+
last_x = 0
34+
last_y = 0
35+
36+
while True:
37+
x = 1023 - seesaw.analog_read(14)
38+
y = 1023 - seesaw.analog_read(15)
39+
40+
if (abs(x - last_x) > 3) or (abs(y - last_y) > 3):
41+
print(x, y)
42+
last_x = x
43+
last_y = y
44+
45+
buttons = seesaw.digital_read_bulk(button_mask)
46+
47+
if not buttons & (1 << BUTTON_X):
48+
print("Button x pressed")
49+
50+
if not buttons & (1 << BUTTON_Y):
51+
print("Button Y pressed")
52+
53+
if not buttons & (1 << BUTTON_A):
54+
print("Button A pressed")
55+
56+
if not buttons & (1 << BUTTON_B):
57+
print("Button B pressed")
58+
59+
if not buttons & (1 << BUTTON_SELECT):
60+
print("Button Select pressed")
61+
62+
if not buttons & (1 << BUTTON_START):
63+
print("Button Start pressed")
64+
65+
time.sleep(0.01)

0 commit comments

Comments
 (0)