Difference between revisions of "6 Play MIDI music"
(Created page with "=Music= We provide a MIDI playback function module, it can be specified on the buzzer PWM output, thus playing out music, although you may not need to know this. Well, witho...") |
(No difference)
|
Revision as of 02:40, 18 February 2019
Music
We provide a MIDI playback function module, it can be specified on the buzzer PWM output, thus playing out music, although you may not need to know this.
Well, without further nonsense, click on music, the board has been pre-connected to a built-in buzzer, its pin position is 25.
A side note: don't install a piezoelectric buzzer. It only plays a single tone.
The code is as follows (refer to the Microbit documentation for the interface)
import music music.play(music.NYAN)
You can see the following list, which is our built-in music.
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
Pick some out and listen. There should be something you like
Create a song of your own
To write a list of Python [" c4:4 ", "D4", "C", "e8 "] is to write a music.
How do you understand that?
Each element can be thought of as a note whose format follows:
NOTE[octave][:duration]
The first step is to have a little basic understanding of music theory.
NOTE refers to the scale of this node. In common terms, C, D, E, F, G, A, B in music are scales. For example, "C" refers to do, so C, D, E, F, G, A, B is do, re, mi, fa, so, la xi.
Octave refers to the octave of this node, octave refers to the interval relationship. To put it simply, you sing 1, 2, 3, 4, 5, 6, 7, 1 (note: CDEFGAB for 1234567). The first one is the lower octave of the last one, and the last one is the higher octave of the first one.
Duration refers to the number of duration of notes played by the node.
For example:
"C4:4" corresponds to the note of C (Do) in the 4 (middle part), and then :4 refers to the duration of four beats, the default duration of which is 125 ms, that is, the duration of play is 0.5s.
If you name the node NOTE R then the speaker won't play any sound for the specified amount of time.
To explain this, let's look at the case in the following chapter.