mirror of
https://github.com/pybricks/pybricks-api.git
synced 2026-09-11 09:05:07 +00:00
Also activate auto formatting. Bump flake8 and mark black disagreements in setup.cfg.
31 lines
814 B
Python
31 lines
814 B
Python
def wait_for_button(ev3):
|
|
"""
|
|
This function shows a picture of the buttons on the EV3 screen.
|
|
|
|
Then it waits until you press a button.
|
|
|
|
It returns which button was pressed.
|
|
"""
|
|
|
|
# Show a picture of the buttons on the screen.
|
|
ev3.screen.load_image("buttons.png")
|
|
|
|
# Tip: add text or icons to the image to help you
|
|
# remember what each button will do in your program.
|
|
|
|
# Wait for a single button to be pressed and save the result.
|
|
pressed = []
|
|
while len(pressed) != 1:
|
|
pressed = ev3.buttons.pressed()
|
|
button = pressed[0]
|
|
|
|
# Print which button was pressed
|
|
ev3.screen.draw_text(2, 100, button)
|
|
|
|
# Now wait for the button to be released.
|
|
while any(ev3.buttons.pressed()):
|
|
pass
|
|
|
|
# Return which button was pressed.
|
|
return button
|