Welcome to Building:bit Superkit repository
3.Control all RGB lights
Control all RGB lights
Control all RGB lights1. 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 the GB 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 refer to the corresponding .py files of each gameplay.
xxxxxxxxxxfrom microbit import *import neopixelFirst, import the libraries needed for this lesson from microbit: the neopixel library is dedicated to controlling RGB lights;
xxxxxxxxxxRed = (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, 4)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.
Play method 1: We can see that all RGB lights will switch colors every 1 second, red-->green-->blue-->white-->off, and keep looping in this state.
Play method 2: We can see that the 4 RGB lights light up green in turn, with a time interval of 200ms, and keep looping in this state.
Play method 3: We can see that the 4 RGB lights will light up different colors in turn, with a time interval of 200ms, and keep looping in this state.
Method 4: We can see that all RGB lights gradually turn from off to on, then from on to off, and keep looping in this state.
If you need to restart, press the reset button on the back of the micro:bit motherboard.