Skip to content

Commit ec8162d

Browse files
committed
Add "were_pressed" property to cpx
1 parent 84ec65b commit ec8162d

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
@@ -56,6 +56,8 @@
5656
import digitalio
5757
import neopixel
5858
import touchio
59+
import gamepad
60+
5961

6062
__version__ = "0.0.0-auto.0"
6163
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_CircuitPlayground.git"
@@ -86,6 +88,7 @@ def __init__(self):
8688
self._a.switch_to_input(pull=digitalio.Pull.DOWN)
8789
self._b = digitalio.DigitalInOut(board.BUTTON_B)
8890
self._b.switch_to_input(pull=digitalio.Pull.DOWN)
91+
self.gamepad = gamepad.GamePad(self._a, self._b)
8992

9093
# Define switch:
9194
self._switch = digitalio.DigitalInOut(board.SLIDE_SWITCH)
@@ -475,6 +478,15 @@ def button_b(self):
475478
"""
476479
return self._b.value
477480

481+
@property
482+
def were_pressed(self):
483+
ret = set()
484+
pressed = self.gamepad.get_pressed()
485+
for button, mask in (('A', 0x01), ('B', 0x02)):
486+
if mask & pressed:
487+
ret.add(button)
488+
return ret
489+
478490
@property
479491
def switch(self):
480492
"""

0 commit comments

Comments
 (0)