music
首先,你需要一个扬声器,然后将扬声器与microbit的Pin0与GND相连。详情可看3.5 Music小节。
例子1:
import music
music.play(music.NYAN)
第二行:调用music.play()
方法播放内置音乐"music.NYAN"
。
例子2:
import music
while True:
for freq in range(880, 1760, 16):
music.pitch(freq, 6)
for freq in range(1760, 880, -16):
music.pitch(freq, 6)
第四行到第七行:自定义声音频率,然后通过music.pitch()
方法,将设定频率播放出来。