Music module

micro: bit in, MicroPython a Music module that provides music playback method, but it is worth noting that the control board is not the buzzer, so to add a buzzer in order to hear the effect, the general received pin0 port, and gnd ground, robotbit expansion board is such a connection. If you want Music, pin0 can not be used to do other a role. Note that there is a jumper, can be cut and connected pin0 buzzer. Generally, we have to use the buzzer, so the line is inserted in place of the cap.

music playing music, generally used as prompts an operation state. Play the role of tone.

usage:

import music
music.play(music.NYAN)

music module provides built-in music, we can directly use.

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

Homemade music:

One can make music, in a list denoted octaves of each note (0-8), the delay (the larger the number, the longer the delay), r repose, b falling tone, rising tone #.

import music

tune = ["C4:4", "D4:4", "E4:4", "C4:4", "C4:4", "D4:4", "E4:4", "C4:4",
        "E4:4", "F4:4", "G4:8", "E4:4", "F4:4", "G4:8"]
music.play(tune)

Or simply:

import music

tune = ["C4:4", "D", "E", "C", "C", "D", "E", "C", "E", "F", "G:8",
        "E:4", "F", "G:8"]
music.play(tune)

Intonation: music.pitch (frequency, time delay in milliseconds)

import music
# Continuous alarm sound, high, low
while True:
    for freq in range(880, 1760, 16):
        music.pitch (FREQ, . 6 ) # frequency, the delay in milliseconds
     for FREQ in Range (1760, 880, -16 ):
        music.pitch(freq, 6)

 

Guess you like

Origin www.cnblogs.com/qywyll/p/11895481.html