Step 1: Make it
What is it?
Program your micro:bit to play a famous tune – or one of your own.
These two videos show you what you'll make and how to code it:
Introduction
Coding guide
How it works
- Connect headphones, or amplified speaker to pins 0 and GND on your micro:bit to hear the sound.
- Pin 0 works as an output when we play music on the micro:bit.
- This program uses musical notes to play a famous French folk tune. ‘Frère Jacques’ repeats each bar twice. We could program micro:bit to play the same notes again, but it’s much easier to use iteration (also known as a loop). This program uses loops that play each bar twice to save having to program the same notes twice.
- Recognising patterns like this is part of computational thinking, a way of making sure computer programs are as efficient as possible, using the smallest amount of code to perform a task – or perform piece of music!
![micro:bit attached to headphones, music stave showing first 4 notes of Frère Jacques](https://cdn.sanity.io/images/ajwvhvgo/production/f6fd1c8ecbc9cd7f3f97259486ee523c1b0c6a0c-2723x1876.png?w=653&q=80&fit=max&auto=format)
What you need
- micro:bit (or MakeCode simulator)
- MakeCode or Python editor
- battery pack (optional)
- a pair of headphones, buzzer or amplified loudspeaker
- two crocodile clip leads
Step 2: Code it
Step 3: Improve it
- Speed it up or slow it down by changing the tempo.
- Complete the full tune. The extra notes you’ll need are GAGFEC, CGC but you’ll need to play the first 4 notes for half a beat, not 1 beat. Remember to use loops to make your code more efficient.
- Program other tunes using sheet music or make up your own.
- You can find out more about how micro:bit music works in Python here.
This content is published under a Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) licence.