Example Code for micro:bit-RGB LEDs
Last revision 2025/12/31
This article guides users on programming RGB LEDs with micro:bit, detailing hardware and software setup, wiring, and sample code for controlling LED colors and brightness.
Hardware Preparation
- Math & Automatic expansion board for micro:bit, Quantity: 1
- micro:bit, Quantity: 1
Software Preparation
Makecode graphical programming, Mind+ platform.
Makecode Library Address.
About how to install a software library?
Wiring Diagram
Connect the RGB LED to p15 of micro:bit.
Other Preparation Work
Install the Makecode library from https://github.com/DFRobot/pxt-Math-Automatic.
About how to install a software library?
Sample Code
- Set the brightness of RGB (0~255)

- Set the LED No. 0 to blue

- Set the LED 4 to 8 to yellow

- Set LED 3 to purple

- Light up RGB Matrix Pixel


- RGB LED show Rainbow

Result
- the brightness of the whole LEDs is 138
- the LED 0 lights up in blue
- the LED 4 to 8 light up in yellow
- the LED 3 lights up in purple
- Light up the LED in form of a matrix in purple. X=1, Y=2. (The original point of the matrix is the upper-left corner.)
- the LED 0 to 15 show rainbow color.
Was this article helpful?
