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



Micro python Robot Course 5: Play《Little Star》

Posted by SuFiona on

Learning goal

This lesson learns to control the buzzer on the Tiny-bit microbit robot to play our own song "Little Star".

Preparation:

1.The position of the buzzer on the robot car

image.png 

2.The micro:bit pins connected to the buzzer.

From the hardware interface manual, we can know that the buzzer is directly driven by the micro:bit P0 pin.

image.png 

Code

from microbit import *

import music

display.show(Image.MUSIC_QUAVER)   

# Display a music pattern on the micro:bit dot matrix

 

tune = ["C4:4", "C", "G", "G", "A", "A", "G:8", "F:4",

        "F", "E", "E", "D:4", "D", "C:8", "G:4", "G",

        "F", "F", "E", "E", "D:8", "G:4", "G", "F",

        "F", "E", "E", "D:8", "C4:4", "C", "G", "G",

        "A", "A", "G:8", "F:4", "F", "E", "E", "D:4",

        "D", "C:8"]   # Song little star

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 5-1.

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

image.png

Figure 5-1

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

image.png Figure 5-3

4.After downloading the program, we can hear the Tiny-bit car start playing the music "Little Star".

The code of the experiment:  5.Play《Little Star》.zip

Micro python Robot Course:

0 comments

Leave a comment

Please note, comments must be approved before they are published