Example Code for micro:bit-RGB Car Light

Last revision 2025/12/19

This article provides example code and instructions for controlling RGB car headlights using a micro:bit on the Maqueen V5 robot car, featuring dynamic light patterns and color changes.

Hardware Preparation

  • Maqueen V5 Robot Car: 1 (Purchase Link: https://www.dfrobot.com/product-2937.html)
  • micro:bit Mainboard: 1
  • 3 AA Batteries: 1 set

Software Preparation

  • MakeCode Platform: https://makecode.microbit.org/
  • Maqueen Library: Load via MakeCode Extensions (search for "dfrobot" and select "Maqueen")

Other Preparation Work

  • Ensure the micro:bit mainboard is properly plugged into Maqueen V5.
  • Install the batteries correctly.
  • Turn on the power switch.

Sample Code

Example 1: Light up the car headlights

This example demonstrates that the two headlights are displayed in red for one second, then turned off for one second. This cycle repeats.

Example 2: Change the color of the car headlights

This example demonstrates that the colors of the two headlights are switched at intervals of one second.

Example 3: Background flashing of the car headlights

Maqueen V5 supports the background flashing of the headlights, which is a characteristic function of Maqueen. Just send one instruction, and it can flash cyclically. The number of flashes, the flashing frequency and the flashing color can be set. And it can be interrupted in real time to turn off the headlights.
This function enables the headlights to flash cyclically without affecting other program processes.
Note: This function is mainly used in "on start". When used in "forever", the effect may not be good due to timing reasons.

Example 4: Background Gradient of the Car Headlights

Maqueen V5 supports the gradual display of colorful lights for the headlights in the background. It is a characteristic function of Maqueen. Just send one instruction, and the headlights can gradually display different colors.
This function enables the headlights to change colors when lit without affecting other program processes.
Note: This function is mainly used in "on start". When used in "forever", the effect may not be good due to timing reasons.

Result

  • Example 1: Headlights cycle red for 1s, off for 1s.
  • Example 2: Headlights switch colors every 1s.
  • Example 3: Headlights flash cyclically in the background.
  • Example 4: Headlights gradient colors in the background.

Was this article helpful?

ON THIS PAGE

TOP