5% OFF Over $19, Code: Elephant5; 10% OFF Over $59, Code: Elephant10

Micro:bit piano board Basic Course 2.5 Piano_playing

Posted by Fiona Su on

Micro:bit piano board Basic Course 2.5 Piano_playing

1.Learning goals

In this lesson we mainly learn how to use the music touch return, music button and RGB blocks of Yahboom piano expansion package.

By programming,we will make the micro:bit dot matrix displays different patterns by touching the 5 black buttons and 7 write buttons on the piano expansion board.

2.Programming method

Mode 1 online programming: First, we need to connect the micro:bit to the computer by USB cable. The computer will pop up a USB flash drive and click on the URL in the USB flash drive: http://microbit.org/ to enter the programming interface. Add the Yahboom package https://github.com/lzty634158/YB_Piano to program.

Mode 2 offline programming: We need to open the offline programming software. After the installation is complete, enter the programming interface, click【New Project】, add Yahboom package:

https://github.com/lzty634158/YB_Piano, you can program.

3.Looking for blocks

The following is the location of the building blocks required for this programming.







How to create a new variable: 




4.Combine building block

The summary program is shown below:


Mode=1 means that the low pitch is played.

Mode=2 means that the middle pitch is played.

Mode=3 means that the high pitch is played.

Mode is the variable name that the user can define, but 1, 2, and 3 respectively indicate low, medium, and high. 

Program analysis:

The initial setting variable Mode is 2 (middle pitch), the brightness of the RGB light on the piano expansion board is set to 50, the three lights are set to blue, green, red, and the delay is 5ms.

Infinite loop:

Set the variable key is the value returned after the piano key is touched. Then judge the value of the key, that is, determine which of L, M, and H is touched.

If the L key is touched, the first RGB light (serial number 0) lights up in blue, at this time the piano plays the lowest pitch;

If the M key is touched, the second RGB light (serial number 1) lights up in green, at this time the piano plays the middle pitch;

If the H key is touched, the third RGB light (serial number 2) lights up in red, at this time the piano plays the highest pitch.

5. Experimental phenomena

After the program is successfully downloaded, after the micro:bit piano is powered on normally. 

As shown in Figure 1, the three RGB lights are respectively illuminated in blue, green, and red. At this time, the default tone is played.

As shown in Figure 2, after touching the H key, the third RGB light is lit red, and the pitch played by the piano is the highest; 

As shown in Figure 3, after touching the M key, the second RGB light is lit green, the the pitch played by the piano is middle; 

As shown in Figure 4, after touching the L key, the second RGB light lights is lit blue, and the pitch played by the piano is the lowest.


Figure 1                            Figure 2


Figure 3                           Figure 4

PS: When the battery is used for a long time, the piano board is not powered enough. At this time, the function will not be realized normally. You can replace the new battery or use USB data cable for power supply. The USB data cable power supply mode is shown in the figure below.


 The code of the experiment:  5.Piano_playing.rar


    Buy Yahboom Micro:bit Expansion Board Piano Development Board


    Leave a comment

    Please note, comments must be approved before they are published