Copy the sample code to a folder on the Raspberry Pi.
Open terminal, and then go to the folder you copied the sample.
Run the sample with the following command:
python3 LED_Lights.py
Sample Code
LED_Lights.py
#!/usr/bin/env python3#This sample demonstrates controlling LED lighting.#Install RC Driver HAT library with "pip3 install turta-rcdriverhat"from time import sleepfrom turta_rcdriverhat import Turta_RCDriver#Initializerc = Turta_RCDriver.RCDriver()try:#Activate fan at 50% speed rc.set_fan(50)whileTrue:#Option one: Set all the LED lights in one shot#0 is LED off, 4095 is LED full bright#Parameters: Front, Read, Stop, Left, Right rc.set_leds([1000, 1000, 1000, 1000, 1000])print("LED Brightness: 1000/4096")#Waitsleep(1.0)#Option two: Set the LED lights one by one#0 is LED off, 4095 is LED full bright rc.set_led(Turta_RCDriver.LED_OUT.FRONT, 2000) rc.set_led(Turta_RCDriver.LED_OUT.REAR, 2000) rc.set_led(Turta_RCDriver.LED_OUT.STOP, 2000) rc.set_led(Turta_RCDriver.LED_OUT.LEFT, 2000) rc.set_led(Turta_RCDriver.LED_OUT.RIGHT, 2000)print("LED Brightness: 2000/4096")#Waitsleep(1.0)#Showcase: Fade the front LEDprint("LED is fading in")for b inrange(0, 1000, 5): rc.set_led(Turta_RCDriver.LED_OUT.FRONT, b)sleep(0.05)print("LED is fading out")for b inrange(1000, 0, -5): rc.set_led(Turta_RCDriver.LED_OUT.FRONT, b)sleep(0.05)#Waitsleep(1.0)#Exit on CTRL+CexceptKeyboardInterrupt:print('Bye.')
Result
When you run the sample, it demonstrates different LED brightnesses. The program fades front LED in and out. The example output should be like this:
LED Brightness: 1000/4096
LED Brightness: 2000/4096
LED is fading in
LED is fading out