Welcome to Building:bit Superkit repository
1.Music carousel
Music carousel
Music carousel1. Learning objectives2. Building blocks3. Motor wiring4. Code analysis5. Write and download the program6. Experimental phenomenon
! Note: Due to the structure of the building blocks, the carousel only supports clockwise rotation. That is, the speed needs to be set to -255 during programming, and cannot be set to a positive number.
1. Learning objectives
In this course, we mainly learn how to use Python programming to make the carousel rotate while playing music.
2. Building blocks
For detailed steps of building blocks, please refer to the installation drawings of [Assembly course]-[Carousel] in the materials or the building blocks installation album.
Please make sure that the direction of the L-shaped hole arm of the building block is as shown in the figure below.

3. Motor wiring
Insert the motor wiring on the left side of the car into the M1 interface of the Super:bit expansion board, with the black line close to the battery side;
As shown below:

4. Code analysis
For the program of this course, please see the Music carousel.py file.
from microbit import *import musicimport superbitimport microbitimport neopixelFirst, import the libraries needed for this lesson from microbit: the superbit library is dedicated to the superbit expansion board; the music library is used to play music; the neopixel is used to control the RGB light.
xxxxxxxxxxdisplay.show(Image.HAPPY)np = neopixel.NeoPixel(pin12, 4)display.show(Image.HAPPY): Display a smiley face pattern on the microbit dot matrix;
np = neopixel.NeoPixel(pin12, 4): Initialize the RGB light settings. There are 4 RGB lights in total, connected to the P12 pin of the microbit motherboard (you can check the hardware interface manual);
xxxxxxxxxxwhile True:music.play('E4:4')superbit.motor_control(superbit.M1, -255, 0)np[0] = (255, 0, 0)np.show()...while True: infinite loop
music.play('E4:4'): The buzzer plays a tone. Parameter 1 E4 represents the tone, and parameter 2 4 represents the beat.
superbit.motor_control(superbit.M1, 255, 0): The motor connected to the M1 interface rotates forward at a speed of 255;
np[0] = (255, 0, 0)
np.show(): The first RGB light turns red
5. 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 whether our code has any errors. 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.
6. Experimental phenomenon
After the program is successfully downloaded, turn on the power switch, and a smiley face pattern will be displayed on the micro:bit dot matrix, as shown in the figure below. Then, the carousel rotates clockwise, the buzzer starts playing the music "Ode to Joy", and the RGB will also switch to different colors.

If you need to restart, press the reset button on the back of the micro:bit motherboard.