Countdown to Christmas Makes Challenge 2017 – Day 14

Star Wars

For the BBC micro:bit

Programed in MicroPython

Star Wars theme tune for the BBC micro:bit, coded in MicroPython.

To start the music, just press the A button on your BBC micro:bit and it will play once. To play again, just press the button once more. If you would like the music to play continuously just remove or comment out line 19; if button_a.is_pressed():.

For details on how to connect headphones to your BBC micro:bit, check out Day 1 of my Countdown to Christmas Makes Challenge 2017.

MicroPython Code

# Star Wars
# @KariLawler (Twitter), 14/Dec/17, v1.0
from microbit import *
import music

star_wars = [
    'd4:2', 'd4:2', 'd4:2', 'g4:8', 'd5:8',
    'c5:2', 'b4:2', 'a4:2', 'g5:8', 'd5:4',
    'c5:2', 'b4:2', 'a4:2', 'g5:8', 'd5:4',
    'c5:2', 'b4:2', 'c5:2', 'a4:8', 'd4:4',
    'd4:2', 'g4:8', 'd5:8', 'c5:2', 'b4:2',
    'a4:2', 'g5:8', 'd5:4', 'c5:2', 'b4:2',
    'a4:2', 'g5:8', 'd5:4', 'c5:2', 'b4:2',
    'c5:2', 'a4:8'
]

music.set_tempo(bpm = 120)
while True:
    if button_a.is_pressed():
        music.play(star_wars)

Leave a Reply