Files
pybricks-api/examples/pup/hub_primehub/button_main.py
T
ZPhilo 2a1640f7dc examples/pup/hubs/hub_primehub: fix button
Corrected Bluetooth button name (from BT to BLUETOOTH)
2021-01-28 09:31:41 +01:00

30 lines
729 B
Python

from pybricks.hubs import PrimeHub
from pybricks.parameters import Button, Icon
from pybricks.tools import wait
# Initialize the hub.
hub = PrimeHub()
# Wait for any button to be pressed, and save the result.
pressed = []
while not any(pressed):
pressed = hub.buttons.pressed()
wait(10)
# Display a circle.
hub.display.image(Icon.CIRCLE)
# Wait for all buttons to be released.
while any(hub.buttons.pressed()):
wait(10)
# Display an arrow to indicate which button was pressed.
if Button.LEFT in pressed:
hub.display.image(Icon.ARROW_LEFT_DOWN)
elif Button.RIGHT in pressed:
hub.display.image(Icon.ARROW_RIGHT_DOWN)
elif Button.BLUETOOTH in pressed:
hub.display.image(Icon.ARROW_RIGHT_UP)
wait(3000)