Skip to content



Débutant | MakeCode, Python | Boutons, Son, Écran LED | Itération, Tempo

Étape 1 : Fais-le

Qu'est-ce que c'est ?

Code your own electronic metronome that makes regular beats which you can slow down and speed up as you practice music.


Guide de codage

Ce que vous apprendrez

  • How to adjust the tempo of musical notes played by the micro:bit
  • How to use input buttons and audio outputs to make a useful electronic device

Comment ça marche

  • At the start of the program, it sets the tempo to 100 bpm - beats per minute. This is a standard way of measuring the tempo, or speed, of music.
  • A forever loop keeps the micro:bit playing a short note and then resting for one beat.
  • Vous pouvez entendre le son en connectant un casque à la broche 0 et GND ou sur le haut-parleur intégré du nouveau micro:bit.
  • Appuyez sur le bouton A pour ralentir le tempo de 5 bpm.
  • Appuyez sur le bouton B pour l'accélérer de 5 bpm.
  • Pressing button A and B together shows the current tempo on the LED display output.

Ce dont vous aurez besoin

  • Un micro:bit
  • MakeCode ou éditeur Python
  • un boîtier de piles (optionnel)

Étape 2 : Programme-le

Étape 3 : Améliore-le

  • You may notice that it plays its rhythm slightly slower than an electronic instrument with the same BPM setting - this is because each loop takes one and one sixteenth of a beat, instead of just one beat.
  • You could try and make it more accurate by adding up fractions of a beat to make one whole beat: 1/2 + 1/4 + 1/8 + 1/16 makes 15/16 to add on the 1/16th of a beat that you’re playing the tone for.
  • 'Forever' blocks also add a bit of a delay, so using a ‘while true’ loop inside it will speed up your code and make it more accurate.
  • The code video at the top of this page shows you how to do this.
Grid showing fractions of beats adding up to fifteen 16ths