Skip to content

Activity

Frère Jacques loops

Intermediate | MakeCode, Python | Pins, Sound | Composition, Iteration, Pattern recognition, Sound

Step 1: Make it

What is it?

Program your micro:bit to play a famous tune – or one of your own.

micro:bit attached to headphones, music stave showing first 4 notes of Frère Jacques

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 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 piece of music!

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.