Welcome to Building:bit Superkit repository
2.Control RGB color
Control RGB color
Control RGB color1. Learning objectives2. Code analysis3. Write and download the program4. Experimental phenomenon
1. Learning objectives
In this course, we mainly learn how to control and light up a single RGB light on the superbit expansion board through Python programming.
The 4 RGB lights are located on the expansion board as shown in the figure below.

2. Code analysis
For the program of this course, please see the Control RGB color.py file.
from microbit import *import neopixelFirst, import the libraries needed for this lesson from microbit: the neopixel library is dedicated to controlling RGB lights;
xRed = (255, 0, 0)Orange = (255, 165, 0)Yellow = (255, 255, 0)Green = (0, 255, 0)Blue = (0, 0, 255)Dark_Violet = (148, 0, 211)White = (255, 255, 255)color = (Red, Orange, Yellow, Green, Blue, Dark_Violet, White)display.show(Image.HAPPY)np = neopixel.NeoPixel(pin12, 1)i = 0Define different RGB light colors.
display.show(Image.HAPPY): Display a smiley face pattern on the microbit dot matrix;
np = neopixel.NeoPixel(pin12, 1): Initialize the RGB light settings. There are 4 RGB lights in total (here we only control one light) connected to the P12 pin of the microbit motherboard (you can check the hardware interface manual).
3. Write and download the program
- Open the Mu software and enter the code in the editing window. Note! All English and symbols should be entered in English mode, use the Tab key for indentation, and the last line ends with a blank program.
- Click the thumb 'Check' button to check if there are any errors in our code. If a cursor or underline appears in a line, it means a syntax error. Please check and modify it. If there is no error, the lower left corner will prompt that there is no problem with the detection.

- Click the ‘REPL’ button to check whether the Superbit library has been downloaded. If not, please refer to [Preparation before class] --> [2.4 Python Programming Guide].

- After the program is written, connect the computer and the microbit mainboard with a microUSB data cable, and click the ‘Flash’ button to download the program to the micro:bit mainboard. (You need to click the ‘REPL’ button again to turn off the import library file function before you can download the program normally).

- If the download fails, please confirm whether the microbit is properly connected to the computer via the microUSB data cable and the Superbit Python library has been imported.
4. Experimental phenomenon
After the program is successfully downloaded, the micro:bit dot matrix will display a smiley face pattern, as shown in the figure below. At the same time, we can see that the first RGB light (serial number 0) will switch to a color every 1 second, red-->orange-->yellow-->green-->blue-->indigo-->white, and keep looping in this state.
If you need to restart, press the reset button on the back of the micro:bit motherboard.