Spring Sale: 5% OFF Over $89, Code: Elephant5; 10% OFF Over $149, Code:Elephant10



Microbit Python Tutorials 7: Play the custom music Painters

Posted by SuFiona on

Course7-Play the custom music Painters

Learning goals:

In this lesson, you will learn how to play the music "The Painter."

Code

from microbit import *

import music

display.show(Image.MUSIC_QUAVER)

tune = ["G4:2", "E4:2", "G4:2", "E4:2", "G4:2", "E4:2", "C4:4", "D4:2", "F4:2",

        "E4:2", "D4:2", "G4:4", "E1:4", "G4:2", "E4:2", "G4:2", "E4:2", "G4:2",

        "E4:2", "C4:4", "D4:2", "F4:2", "E4:2", "D4:2", "C4:4", "E1:4", "D4:2",

        "D4:2", "F4:2", "F4:2", "E4:2", "C4:2", "G4:4", "D4:2", "F4:2", "E4:2",

        "D4:2", "G4:4", "E1:4", "G4:2", "E4:2", "G4:2", "E4:2", "G4:2", "E4:2",

        "C4:4", "D4:2", "F4:2", "E4:2", "D4:2", "C4:4"]

music.play(tune) 

Programming and downloading

1.You should open the Mu software, and enter the code in the edit window, , as shown in Figure 7-1.

Note! All English and symbols should be entered in English, and the last line must be a space.

blob.png 

Figure 7-1

2. As shown in Figure 7-2, you need to click the Check button to check if our code has an error. If a line appears with a cursor or an underscore, the program indicating this line is wrong.

blob.png 

Figure 7-2

3.You need to connect the micro data cable to micro:bit and the computer, then click the Flash button to download the program to micro:bit as shown in Figure 7-3.

blob.png 

Figure 7-3

4.After downloading the program to micro:bit, you can hear t the music "Painter", and there is a note on the dot matrix as shown in Figure 7-4.blob.png 

Figure 7-4 

The code of the experiment: 7.Play the custom music Painters.rar

 

0 comments

Leave a comment

Please note, comments must be approved before they are published