micro:bit of Things -- Music

2018-01-04 08:49

17. Music

micro:bit 物聯網 課程 系列  -- 音樂播放

Another fantastic feature of the micro:bit is its ability to generate musical notes. This makes it very easy indeed for even quite young children to program simple songs.

 

Task:

Program the micro:bit to play the first few bars of 'Happy Birthday'.

 

Algorithm:

When button A is pressed.

Display the message Happy Birthday!

Play D

Play D

Play E

Play D

Play G

Play F

Rest

micro:bit的另一個奇妙功能是它能夠生成音符。 這使得即使是非常年幼的孩子也可以很簡單地編寫簡單的歌曲。

 

任務:

編程 micro:bit 播放“生日快樂”的前幾個小節。

 

算法:

按下按鈕A.

顯示消息生日快樂!

玩D

玩D

玩E

玩D

玩G

玩F

休息

 

Model:

There is no model for this task. A small piezo sounder that will operate at 3V must be connected between pin0 and GND.

You can use a speaker with a standard 3.5mm jack plug. See the diagram on the right for the connections when using pin0.

模型:

這個任務沒有模式。 必須在pin0和GND之間連接一個以3V工作的小型壓電式發聲器。

您可以使用標準3.5mm插孔的揚聲器。 使用pin0時,請參見右側的連接圖。

 

PXT Editor script:

 

Micro Python script:

One for Christmas...

(remember you can copy and paste script into the Micr Python editor)

from microbit import *

import music

 

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

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

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

"F4:4", "D4:4", "C4:8"]

 

while True:

if button_a.is_pressed():

music.play(tune)

 

—————

返回