First, make sure you’re familiar with setting up the Circuit Playground Express for use with MakeCode by following this guide. https://learn.adafruit.com/makecode
Once you can successfully create a program with MakeCode and upload it to your board, return here.
You can create songs very easily in MakeCode, by stringing together a series of play (note) for (time) blocks and rest for (time) blocks. For a simple, short melody this works very well, for example, in the embedded MakeCode session here, press the left button on the simulator to hear it play.
Notice how there's a phrase that's repeated twice in that example? I can get pretty tedious to manually enter those same notes and durations over and over again -- so we can instead, turn that one phrase into a reusable mini program within a program! That's what a function is -- a chunk of code that can be referenced easily elsewhere in our program.
In this example, one set of the notes that make up the phrase have been moved into a function block (functions are found in the Advanced section). You can click Make a Function to create a function block -- give it a good, memorable name, in this case 'phrase01'.
Then, you can use the call function phrase01 block wherever you want to repeat the phrase.
Here's what it looks like when we add a couple more phrases and then start to sequence them in the on button A click block.
Notice how we've been building the song inside the on button A click block. If we wanted to also play the song when right button (button B) is pressed, for example, we would have to copy the entire set of blocks and repeat it in two places. This works, but there's a more efficient way -- that's to build another function block that itself is filled with function blocks!
The new function could be named song01 and it is full of calls to the other functions that are the phrases that make up the roadmap for the song.
Here's the full song -- notice how the song function contains many repetitions of the phrases to compose the entire song.
Here's another favorite -- the theme song from Where in the World is Carmen Sandiego.
Here's the beginning of the Mission: Impossible theme. Can you add to it? Maybe make it loop a few more times on button A click?
You can have fun creating other favorite spy themes, such as:
- Get Smart
- Bloodhound Gang
- Pink Panther
Or, really personalize it and write your own cool theme!
Page last edited March 08, 2024
Text editor powered by tinymce.