Move Hub: Built-in button changes built-in led color. #1256
-
I have a Move Hub and I want to change the color of the hub's built-in led everytime when I press built-in hub button Here is my NOT WORKING code.
Thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
Hello, Maybe some more info might help? What firmware do you use? To reproduce Expected behavior Next to these remarks I ran this code on my move hub: from pybricks.hubs import MoveHub
from pybricks.parameters import Color, Button
from pybricks.tools import wait, StopWatch
from pybricks import version
print(version)
wait(2000)
hub = MoveHub()
value = 1
hub.system.set_stop_button(None)
hub.system.set_stop_button(None)
hub.system.set_stop_button(None)
hub.system.set_stop_button(None)
watch = StopWatch()
while watch.time() < 5000:
if hub.button.pressed():
hub.light.on(Color.GREEN)
value = (value % 3) + 1
wait(100)
else:
hub.light.on(Color.RED)
print(value)
wait(100)
hub.system.set_stop_button(Button.CENTER)
wait(5000)
Will update firmware and retry.. Bert [EDIT} This program works for me: from pybricks import version
from pybricks.hubs import MoveHub
from pybricks.parameters import Color, Button
from pybricks.tools import wait, StopWatch
print(version)
wait(500)
hub = MoveHub()
# skipped Blue to show "normal" state
colors = {1: Color.BLACK, 2: Color.NONE, 3: Color.BROWN, 4: Color.CYAN,
5: Color.GRAY, 6: Color.GREEN, 7: Color.MAGENTA, 8: Color.ORANGE,
9: Color.RED, 10: Color.VIOLET, 11: Color.WHITE}
num_colors = len(colors)
print("color has", num_colors, "colors")
hub.system.set_stop_button(None)
value = 0
print("Ready to press the button to change the hub light color")
for __ in range(num_colors): # do once for each color
while not hub.button.pressed():
wait(100) # wait a bit if no button pressed
value += 1
print(hub.button.pressed(), "go to color", value, colors[value])
hub.light.on(colors[value])
wait(500)
# Back to "normal"
hub.light.on(Color.BLUE)
print("Set Button.CENTER as STOP button again")
hub.system.set_stop_button(Button.CENTER)
wait(10000) Does this help? Bert |
Beta Was this translation helpful? Give feedback.
-
Yes your code works! Now I actually want to run the motors with this line up (A - B - C - D - A and B - C and D). Can you help me? I just tried myself but I get errors. My code:
|
Beta Was this translation helpful? Give feedback.
Hello,
Maybe some more info might help?
What firmware do you use?
To reproduce
You already decribed that.
Expected behavior
What did you expect to happen instead?
Next to these remarks I ran this code on my move hub: