Blocks from the Music Category¶
The category contains blocks which reproduce tones/melodies, the block that serves as a “trigger” for activating the program when a melody is played, as well as the block for storing the values of basic tones and their duration in milliseconds.
Let’s create a program which plays the tone D for 1/4 beat when button A is pressed.
We will have to drag the block from the category
onto the work surface, and then we insert the block
into it.
From the drop-down lists of the given block, we will choose the tone and its duration in milliseconds.
![_images/p20.png](https://petljamediastorage.blob.core.windows.net/root/Media/Default/Kursevi/international/BlockBasedProgMakeCodeEng/p20.png)
Note: Sound is heard through speakers or headphones connected to the computer.
The final look of the code:
![_images/p21.png](https://petljamediastorage.blob.core.windows.net/root/Media/Default/Kursevi/international/BlockBasedProgMakeCodeEng/p21.png)
To test the program, we can run it in the simulator by clicking on the button.
Task. Create a program, which will play the melody of the song “London Bridge”.
You should use these notes:
g, a, g, f, e, f, g
d, e, f, e, f, g
g, a, g, f, e, f, g
d, g, e, c.
You can compare your solution with ours: https://makecode.microbit.org/_LW3UUKAzocbo
If we want to play a melody (a series of notes lasting a certain amount of time, and played one after the other) we use the block , from the drop-down list of this block we will choose the melody and how long it will last (whether it will be played once, forever, …)
The final look of the code:
![_images/p23.png](https://petljamediastorage.blob.core.windows.net/root/Media/Default/Kursevi/international/BlockBasedProgMakeCodeEng/p23.png)
To test the program, we can run it in the simulator by clicking on the button.