Melodies
Music is made of melodies. The Micro:bit library is designed with a rich collection of pre-loaded melodies. We can play a simple melody on the Micro:bit using the music
module. The module contains 21 melodies. Some of the most popular ones are as follows:
music.DADADADUM music.PRELUDE music.RINGTONE music.BIRTHDAY music.WEDDING music.BADDY music.POWER_UP music.POWER_DOWN
We can access the complete list using the dir(music)
command. Connect your Micro:bit to your PC and run the following simple MicroPython code to play any of these melodies:
import music music.play(music.BLUES)
We can play multiple melodies by pressing different buttons on the Micro:bit. In the following code, we are playing two different melodies by pressing buttons A and B on the Micro:bit. The following code will play the FUNK
melody when button A is pressed and the DADADADUM
melody when button B is pressed:
import music from microbit import * while True: if button_a...