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



Microbit Python Tutorials 6: Sing a song

Posted by SuFiona on

Course6-Sing a song

Learning goals:

In this lesson, you can use the micro:bit robot to play music, the robot sings a happy birthday song, and the dot matrix displays a buzzer pattern.

Code

from microbit import *

import music

boat = Image("00090:90990:99990:90990:00090")

display.show(boat)

music.play(music.BIRTHDAY) 

Below is a complete list of melody:

• music.DADADADUM
• music.ENTERTAINER 
• music.PRELUDE
• music.ODE
• music.NYAN
• music.RINGTONE
• music.FUNK
• music.BLUES
• music.BIRTHDAY
• music.WEDDING
• music.FUNERAL
• music.PUNCHLINE
• music.PYTHON
• music.BADDY
• music.CHASE
• music.BA_DING
• music.WAWAWAWAA
• music.JUMP_UP
• music.JUMP_DOWN
• music.POWER_UP
• music.POWER_DOWN  

Programming and downloading

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

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

Figure 6-1

2.As shown in Figure 6-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 6-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 6-3.

blob.png 

Figure 6-3

4.After downloading the program, you can hear Micro:bit playing Happy Birthday and a buzzer on the micro:bit dot matrix. as shown in Figure 6-4.

blob.png

Figure 6-4

The code of the experiment: 6.Sing a song.rar

Last Microbit Tutorial >> Microbit Python Tutorials 5: See who is pressing fast
Next Microbit Tutorial >> Microbit Python Tutorials 7: Play the custom music Painters

 

0 comments

Leave a comment

Please note, comments must be approved before they are published