Control RGB Lights
Through the light control API provided by MyAGVPlus, you can take over the LED light strips surrounding the chassis and customize the color and brightness to your liking.
1 API Description
Controlling the RGB light strips mainly involves two APIs:
set_led_mode(mode): Set the LED mode.0means restoring the system's default battery indicator marquee mode, and1means switching to the developer's custom color mode.set_led_color(brightness, color): In custom mode, set the brightness and color of the light strips.brightnessranges from 0-255, andcoloris a tuple containing three RGB color values, such as(255, 0, 0)which represents solid red.
2 Simple Demo
Create a new Python file named control_rgb.py and enter the following code:
from pymycobot.myagvplus import MyAGVPlus
import time
# Initialize the MyAGVPlus object
# The serial port paths depend on the actual device, such as /dev/myagvplus_controller and /dev/ttyACM0
agv = MyAGVPlus('/dev/myagvplus_controller', baudrate=921600, esp32_port='/dev/ttyACM0', esp32_baud=115200, debug=True)
# Power on the robot (includes relay power-on and motor enabling, requires a few seconds to wait)
agv.power_on()
print("Switch LED to custom control mode")
agv.set_led_mode(1)
time.sleep(0.5)
print("Set the light to: Red")
agv.set_led_color(255, (255, 0, 0))
time.sleep(2)
print("Set the light to: Green")
agv.set_led_color(255, (0, 255, 0))
time.sleep(2)
print("Set the light to: Blue")
agv.set_led_color(255, (0, 0, 255))
time.sleep(2)
print("Restore system default battery indicator mode")
agv.set_led_mode(0)
# After running, turn off the power (and disable motors)
agv.power_off()
3 Run the Example File
Enter the following command in the terminal to run the code:
python3 control_rgb.py
After execution, the chassis light strips of the robot will sequentially display bright red, solid green, and solid blue for 2 seconds each, and then restore the default battery marquee indicator effect.