I tried making a "Code Snippet"

I tried making a “Code Snippet” and assigning it to an event, but I can’t get it to work.
Is this code correct?
motors = MotorsController()
led_1 = LEDController(“LED1”)
motors.set_forward_rate(1, 100)
motors.set_speed(1, 512) # ~25% speed
led_1.set_led_effect(0, 500, 255, 0b0001, 0xFFFFFF) # White

Check here, these two are working. Maybe that helps.

motors = MotorsController()
motors.set_speed(2, 1024)
time.sleep(2)
motors.set_speed(2, 0)
time.sleep(2)
motors.set_speed(2, 2048)
time.sleep(2)

And this:

led_controller = LEDController(“LED1”)
led_controller.set_led_effect(0, 1000, 5, 0b1111, 0xFF0000)
led_controller.timing_proc()

2 Likes

Thanks my friend, the motor snippet works, but the LED snippet doesn’t.

it works here. You sure about “LED1”? Important: don’t forget the timing_proc()

Yes, I’m sure, but I’ll try again later.

I too can not get the LED to work.
Is this the complete code I need to put in ?

Maybe this will help to get access to the LEDs:

SHIPPET 1 Turn on headlights and taillights

from leds import LEDController
led_vorne = LEDController("LED1")  # Front LED
led_hinten = LEDController("LED2")  # Rear LED
# Stop effects!
led_vorne.repeat_count = 0
led_hinten.repeat_count = 0
# Set LEDs MANUALLY
led_vorne.np[1] = led_vorne.np[2] = (255, 255, 255)  # White
led_hinten.np[1] = led_hinten.np[2] = (128, 0, 0)     # Red 50%
led_vorne.np.write()
led_hinten.np.write()

SHIPPET 2 Turn off front & rear lights

from leds import LEDController
led_vorne = LEDController("LED1")  # Front LED
led_hinten = LEDController("LED2")  # Rear LED
# Stop effects
led_vorne.repeat_count = 0
led_hinten.repeat_count = 0
# Turn off LEDs
led_vorne.np[1] = led_vorne.np[2] = (0, 0, 0)
led_hinten.np[1] = led_hinten.np[2] = (0, 0, 0)
led_vorne.np.write()
led_hinten.np.write()

It’s an example for two Shippets for a CyberBrick car … Take a look here!

Regards Birdy