Play the bass and the treble with this micro:bit pop song cover!
A superstar in both the US and the UK, Meghan Trainor's all about girl power, rocking a retro look... and of course she's also All About That Bass.
Once again we'll be using Python to put this song together. However, this time we're going one step further - not only are we doing the melody... you know we'll be doing the bassline too!
First off, we need to define what Python modules we're using. We want to play music in this script, so of course we're using the Music module!
We also need to state how quickly the song should play. Your micro:bit sets a default tempo of 120 Beats Per Minute (BPM) but All About That Bass is slightly faster - 135 BPM.
Composing the Melody
To start with, let's build the melody. We really like the bridge just before the song's chorus - the lyrics of it go like this:
Yeah, my momma she told me don't worry about your size
She says, boys they like a little more booty to hold at night
You know I won't be no stick-figure, silicone Barbie doll,
So, if that's what's you're into
Then go ahead and move along
The melody here breaks down really nicely into repeating phrases. Here's how we've cut up the melody:
- "Yeah my momma she told me don't worry about your-" and "You know I won't be no stick-figure, silicone Barbie-"
- "She says: Boys, they like a little more booty to hold-" and "So, if that's what's you're into then go ahead and move-"
- "At night"
Writing the long song chunks
The way we've split up the chorus gives us two longer lists and two short lists.
Here are the two longer lists written out in Python:
Writing the shorter song chunks
Each of the long bits of melody is paired with a shorter melody to end each line. These small parts are really fun to sing along to!
Here are all four shorter parts:
Putting it all together
Now we have the main parts of our chorus written in lists, we can tell our micro:bit what order to play them in.
We want the music to play while the micro:bit is on, so first we'll type in 'while True:'.
Now we can start playing our music. The code for playing music is 'music.play()' with the name of a list or specific music notes inside the brackets.
Our lists cover almost all of the song and the pattern is really simple, but there are a few pauses and an extra note that need to be added in to have the final result sounding perfect. Here's what the playback code should look like:
Remember to make sure that the names of your lists here match the ones you wrote earlier. If anything is spelled differently, Python will get confused and give you an error!
Flash your code to your micro:bit and have a listen to the results! If there's an error don't panic - your micro:bit will tell you what line the problem is on, so look carefully and see if there's a spelling mistake or an indentation that's missing.
Bonus: Make the bassline, too!
It wouldn't be All About that Bass without... the bass, right? So here's a quick script to do the bassline, too.
Start a new Python script for this one, using the same tempo as the melody we've just written.
The bassline is very simple, so instead of building the full tune out of multiple lists, we can use just the one list here.
Oh, and a hint for you - in Python, as long as the contents of list is kept inside [square brackets] and each item is separated by a comma, you don't need to write all of your list on one line.
This means that for a long list like the one we're about to write, we can split up the contents into lines and make it much easier to read.
Since it's just the one list, playback is really simple - use the 'music.play()' command to get the bass pumpin'.