Skip to content

Commit 0c96237

Browse files
authored
Merge pull request #1 from deshipu/master
@deshipu added "were_pressed" property to cpx
2 parents a54bb0f + ec8162d commit 0c96237

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

adafruit_circuitplayground/express.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@
6060
import digitalio
6161
import neopixel
6262
import touchio
63+
import gamepad
64+
6365

6466
__version__ = "0.0.0-auto.0"
6567
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_CircuitPlayground.git"
@@ -90,6 +92,7 @@ def __init__(self):
9092
self._a.switch_to_input(pull=digitalio.Pull.DOWN)
9193
self._b = digitalio.DigitalInOut(board.BUTTON_B)
9294
self._b.switch_to_input(pull=digitalio.Pull.DOWN)
95+
self.gamepad = gamepad.GamePad(self._a, self._b)
9396

9497
# Define switch:
9598
self._switch = digitalio.DigitalInOut(board.SLIDE_SWITCH)
@@ -479,6 +482,15 @@ def button_b(self):
479482
"""
480483
return self._b.value
481484

485+
@property
486+
def were_pressed(self):
487+
ret = set()
488+
pressed = self.gamepad.get_pressed()
489+
for button, mask in (('A', 0x01), ('B', 0x02)):
490+
if mask & pressed:
491+
ret.add(button)
492+
return ret
493+
482494
@property
483495
def switch(self):
484496
"""

0 commit comments

Comments
 (0)