Making music with micro:bit
Note: A microPython version of this tutorial can be found here: Making music with the micro:bit - MicroPython version - teachwithict.com
What you will need:
- Web enabled device (PC, Tablet, Phone) with an up-to-date browser (Internet Explorer, Safari, Chrome)
- BBC micro:bit simulator (Micro:bit Educational Foundation | micro:bit (microbit.org))
- BBC micro:bit (Optional)
- Speaker or headphones & two crocodile clips (Optional)
Making music with Make Code:
The built-in music library in Make Code allows us to play music on our micro:bit.
To play a note we use the following command
The built-in music library in Make Code allows us to play music on our micro:bit.
To play a note we use the following command
Where Middle C = note and 1 beat = duration.
Example
Try the following example:
Example
Try the following example:
Did you recognise the tune
Transcribing songs from sheet music
If we want to re-create our favourite songs on our micro:bit, we first need a basic understanding of sheet music.
Here’s a reminder of the most common notes used in a musical score:
The Treble Clef
If we want to re-create our favourite songs on our micro:bit, we first need a basic understanding of sheet music.
Here’s a reminder of the most common notes used in a musical score:
The Treble Clef
Below is the score for a very popular piece of music - Can you can guess what it is?
Answer: Grande Valse (You may know it as the ‘Nokia Ringtone’)
Did you notice the special # symbols at the start of the score. This shows that some of the notes are sharps. In this case, the sharp notes are:
F#, C#, and G#
In Make Code, sharp notes are selected by clicking on the ‘black notes’ in the drop-down keyboard:
Did you notice the special # symbols at the start of the score. This shows that some of the notes are sharps. In this case, the sharp notes are:
F#, C#, and G#
In Make Code, sharp notes are selected by clicking on the ‘black notes’ in the drop-down keyboard:
Below is the music score for the Nokia Ringtone (this time with notes underneath).
It’s all about the timing
If we look at the notes in a music score again, you will notice that they’re different shapes and colours. These different shapes and colours denote the timings. (See below)
Notice that some of the notes have a dot (or full stop) after them. For these notes, we need to multiply the duration by 1.5.
Below is the score again however, this time, with timings (duration).
Rests
Rests are natural pauses or breaks in a piece of music. Rests can be added to your code using the following command:
Rests are identified by the following symbols:
Challenge
- Program your micro:bit to play the Nokia ringtone.
- Use a loop to repeat the ringtone 4 times (or forever if you want to be really annoying!)
- Modify your code so that the ringtone only plays when you press the ‘A’ button
Resources
Sheet music:
Playing music through your micro:bit
Option 1 - Buzzer
Wiring instructions
Option 1 - Buzzer
Wiring instructions
- Disconnect the micro:bit from your computer and disconnect the battery pack.
- Using crocodile clips, connect the longer leg (or + side) to Pin 0, and the shorter leg to GND on the BBC micro:bit.
Option 2 - Headphones
Wiring instructions
- Disconnect the micro:bit from your computer and disconnect the battery pack.
- Using crocodile clips, connect the tip of the mini-jack to Pin 0, and the base of the mini jack to GND on the BBC micro:bit.
Useful links:
Micro:bit Music Fest - All the tools you need to make your own micro:bit band.
MicroPython - MicroPython music reference guide.
Play Tone - Reference guide for making music with Make Code.
Somebody to You: The Vamps - Learn how to play 'Somebody to You' by the Vamps on your BBC micro:bit using MicroPython.
Licence:
Unless otherwise specified, everything in this repository is covered by the following licence:
BBC micro:bit "Magic 8-Ball" lesson is licenced under a Creative Commons Attribution 4.0 International License.