mirror of
https://github.com/pybricks/pybricks-api.git
synced 2026-09-12 17:46:19 +00:00
These code samples are rendered in the docs, so we include them here. For the git history of these snippets, see: https://github.com/pybricks/pybricks-projects/commits/f4914069aaacfd9ab1e0dd6f05524f62cfc56b29/snippets
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
|