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
28 lines
739 B
Python
28 lines
739 B
Python
#!/usr/bin/env pybricks-micropython
|
|
|
|
from pybricks.hubs import EV3Brick
|
|
from pybricks.parameters import Button
|
|
|
|
from menu import wait_for_button
|
|
|
|
# Initialize the EV3.
|
|
ev3 = EV3Brick()
|
|
|
|
while True:
|
|
# Show the menu and wait for one button to be selected.
|
|
button = wait_for_button(ev3)
|
|
|
|
# Now you can do something, based on which button was pressed.
|
|
|
|
# In this demo, we just play a different sound for each button.
|
|
if button == Button.LEFT:
|
|
ev3.speaker.beep(200)
|
|
elif button == Button.RIGHT:
|
|
ev3.speaker.beep(400)
|
|
elif button == Button.UP:
|
|
ev3.speaker.beep(600)
|
|
elif button == Button.DOWN:
|
|
ev3.speaker.beep(800)
|
|
elif button == Button.CENTER:
|
|
ev3.speaker.beep(1000)
|