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

  1. Set the brightness of RGB (0~255)
    Set Brightness
  2. Set the LED No. 0 to blue
    LED NO.0 Blue
  3. Set the LED 4 to 8 to yellow
    LED 4 to 8 light up in yellow
  4. Set LED 3 to purple
    LED 4 light up in purple
  5. Light up RGB Matrix Pixel
    Light up RGB matrix pixel
    Matrix Pixel
  6. RGB LED show Rainbow
    RGB LED show rainbow

Result

  1. the brightness of the whole LEDs is 138
  2. the LED 0 lights up in blue
  3. the LED 4 to 8 light up in yellow
  4. the LED 3 lights up in purple
  5. 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.)
  6. the LED 0 to 15 show rainbow color.

Was this article helpful?

TOP