Skip to content

Add "were_pressed" property to cpx #51

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions adafruit_circuitplayground/express.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@
import digitalio
import neopixel
import touchio
import gamepad


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

# Define switch:
self._switch = digitalio.DigitalInOut(board.SLIDE_SWITCH)
Expand Down Expand Up @@ -475,6 +478,15 @@ def button_b(self):
"""
return self._b.value

@property
def were_pressed(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs a docstring.

ret = set()
pressed = self.gamepad.get_pressed()
for button, mask in (('A', 0x01), ('B', 0x02)):
if mask & pressed:
ret.add(button)
return ret

@property
def switch(self):
"""
Expand Down