pybricks.pupdevices.Remote: Light examples.

This commit is contained in:
Laurens Valk
2021-08-05 14:56:00 +02:00
parent 5d4481dbb0
commit 8a6ddf677c
3 changed files with 71 additions and 0 deletions
+44
View File
@@ -0,0 +1,44 @@
from pybricks.pupdevices import Remote
from pybricks.parameters import Button, Color
def button_to_color(buttons):
# Return a color depending on the button.
if Button.LEFT_PLUS in buttons:
return Color.RED
if Button.LEFT_MINUS in buttons:
return Color.GREEN
if Button.LEFT in buttons:
return Color.ORANGE
if Button.RIGHT_PLUS in buttons:
return Color.BLUE
if Button.RIGHT_MINUS in buttons:
return Color.YELLOW
if Button.RIGHT in buttons:
return Color.CYAN
if Button.CENTER in buttons:
return Color.VIOLET
# Return no color by default.
return Color.NONE
# Connect to the remote.
remote = Remote()
while True:
# Wait until a button is pressed.
pressed = ()
while not pressed:
pressed = remote.buttons.pressed()
# Convert button code to color.
color = button_to_color(pressed)
# Set the remote light color.
remote.light.on(color)
# Wait until all buttons are released.
while pressed:
pressed = remote.buttons.pressed()
+15
View File
@@ -0,0 +1,15 @@
from pybricks.pupdevices import Remote
from pybricks.parameters import Color
from pybricks.tools import wait
# Connect to the remote.
remote = Remote()
while True:
# Set the color to red.
remote.light.on(Color.RED)
wait(1000)
# Set the color to blue.
remote.light.on(Color.BLUE)
wait(1000)