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



Micro Python Basic Course 7: Play built-in music

Posted by SuFiona on

Learning goals:

This lesson learns to play built-in music by Python programming. For example: heart.

Code:

from microbit import *

import music

music.play(music.ODE)

We need to import the music library function, and call the built-in music. WEDDING melody from the library, the following 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 7-1.

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

image.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.

image.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 2-3.

image.png Figure 7-3

4. After the download is successful, we need to connect P0,GND of micro:bit to head phone by crocodile clip. Then, you can hear that buzzer play ODE .

image.png 

The code of the experiment: 7.Play built-in music.zip

Micro Python Basic Course

0 comments

Leave a comment

Please note, comments must be approved before they are published