本帖最后由 dcexpert 于 2019-5-19 20:56 编辑
蜂鸣器
microbit 默认使用pin0控制蜂鸣器,可以用来播放音乐。
- from microbit import *
- import music
- #直接播放内置音乐
- music.play(music.POWER_UP)
- music.play(music.PYTHON)
- #后台播放音乐
- music.play(music.PYTHON, wait = 0)
- #后台循环播放音乐
- music.play(music.PYTHON, wait = 0, loop=1)
- #播放自定义音乐
- from microbit import *
- import music
- # MoonRive 月亮河
- music.set_tempo(ticks=16, bpm=90)
- tune = ['G5:32', 'D6:12', 'C:24', 'B5', 'A:6', 'G:8', 'F', 'G:32', 'B:24',
- 'A:8', 'G', 'F', 'G:32', 'E:12', 'D:48', 'R:16', 'D:8', 'C:32', 'G:16',
- 'E:24', 'D:8', 'C:48', 'G:16', 'E:24', 'D:12', 'C', 'E:16', 'G', 'C6',
- 'B5', 'A:8', 'B:16', 'A', 'G:12', 'A:48']
- music.play(tune)
- from microbit import *
- import music
- # Beethoven 致爱丽丝
- music.set_tempo(ticks=16, bpm=125)
- tune = ['E6:8', 'D#', 'E', 'D#', 'E', 'B5', 'D6', 'C', 'A5:16', 'R6:8', 'C5',
- 'E', 'A', 'B:16', 'R6:8', 'E5', 'G#', 'B', 'C6:16', 'R:8', 'E5', 'E6',
- 'D#', 'E', 'D#', 'E', 'B5', 'D6', 'C', 'A5:16', 'R6:8', 'C5', 'E', 'A',
- 'B:16', 'R6:8', 'E5', 'C6', 'B5', 'A:16']
- music.play(tune)
复制代码
下面一首音乐是什么?第一位正确回复的网友可以获取10芯币的奖励。
- from microbit import *
- import music
- music.set_tempo(ticks=16, bpm=100)
- tune = ['A5:16', 'A', 'A#', 'C6', 'C', 'A#5', 'A', 'G', 'F', 'F', 'G', 'A',
- 'A:24', 'G:8', 'G:32', 'A:16', 'A', 'A#', 'C6', 'C', 'A#5', 'A', 'G',
- 'F', 'F', 'G', 'A', 'G:24', 'F:8', 'F:32', 'G:16', 'G', 'A', 'F', 'G',
- 'A:8', 'A#', 'A:16', 'F', 'G', 'A:8', 'A#', 'A:16', 'G', 'F', 'G', 'C',
- 'A:32', 'A:16', 'A#', 'C6', 'C', 'A#5', 'A', 'G', 'F', 'F', 'G', 'A',
- 'G:24', 'F:8', 'F:32']
- music.play(tune)
复制代码
此内容由EEWORLD论坛网友dcexpert原创,如需转载或用于商业用途需征得作者同意并注明出处
|