Home Code Playing Micro:bit built in tunes with Micropython

Playing Micro:bit built in tunes with Micropython

by shedboy71

For the purposes of education and entertainment, the module contains several example tunes that are expressed as Python lists. They can be used like this:

import music
music.play(music.NYAN)

All the tunes are either out of copyright, composed by Nicholas H.Tollervey and released to the public domain or have an unknown composer and are covered by a fair (educational) use provision.

The tunes are:

DADADADUM – the opening to Beethoven’s 5th Symphony in C minor.
ENTERTAINER – the opening fragment of Scott Joplin’s Ragtime classic “The Entertainer”.
PRELUDE – the opening of the first Prelude in C Major of J.S.Bach’s 48 Preludes and Fugues.
ODE – the “Ode to Joy” theme from Beethoven’s 9th Symphony in D minor.
NYAN – the Nyan Cat theme (http://www.nyan.cat/). The composer is unknown. This is fair use for educational porpoises (as they say in New York).
RINGTONE – something that sounds like a mobile phone ringtone. To be used to indicate an incoming message.
FUNK – a funky bass line for secret agents and criminal masterminds.
BLUES – a boogie-woogie 12-bar blues walking bass.
BIRTHDAY – “Happy Birthday to You…” for copyright status see: http://www.bbc.co.uk/news/world-us-canada-34332853
WEDDING – the bridal chorus from Wagner’s opera “Lohengrin”.
FUNERAL – the “funeral march” otherwise known as Frédéric Chopin’s Piano Sonata No. 2 in B♭ minor, Op. 35.
PUNCHLINE – a fun fragment that signifies a joke has been made.
PYTHON – John Philip Sousa’s march “Liberty Bell” aka, the theme for “Monty Python’s Flying Circus” (after which the Python programming language is named).
BADDY – silent movie era entrance of a baddy.
CHASE – silent movie era chase scene.
BA_DING – a short signal to indicate something has happened.
WAWAWAWAA – a very sad trombone.
JUMP_UP – for use in a game, indicating upward movement.
JUMP_DOWN – for use in a game, indicating downward movement.
POWER_UP – a fanfare to indicate an achievement unlocked.
POWER_DOWN – a sad fanfare to indicate an achievement lost.

 

Code

[codesyntax lang=”python”]

from microbit import *

import music
built_in_tunes = [music.DADADADUM, music.ENTERTAINER, music.PRELUDE, music.ODE, music.NYAN, music.RINGTONE, music.FUNK, music.BLUES,
music.BIRTHDAY, music.WEDDING, music.FUNERAL, music.PUNCHLINE,music.PYTHON, music.BADDY, music.CHASE, music.BA_DING, 
music.WAWAWAWAA, music.JUMP_UP, music.JUMP_DOWN, music.POWER_UP, music.POWER_DOWN]

while True:
    for tune in built_in_tunes:
        music.play(tune)
        sleep(2000)

[/codesyntax]

You may also like

Leave a Comment