To make your glove musical, you'll use the CPX like a synthesizer. A synthesizer works by producing an electrical signal and altering it in special ways to create different sounds. Then it sends the signal to a speaker, which translates the changes in voltage into sound wave frequencies you can hear.

Programming the CPX to play a note or musical phrase is super easy with Microsoft MakeCode. This drag-and-drop visual language has music blocks that you can adjust in multiple ways. For this project, you'll start with a single note or series of notes, then vary the sound by changing four things:

  • the pitch (how high or low the notes sounds),
  • the duration of the note (how long or short it is compared to other notes)
  • the tempo (how fast or slow they play),
  • and the volume (how loud or soft they sound).

If you haven't made your own music before with MakeCode, this page will give you a quick run-down. And if you're new to MakeCode and want to learn more, you can find a full getting-started guide by clicking the button below.

Using the Music Menu

Open MakeCode online or the MakeCode for Adafruit app on your computer and click on the Music menu. You'll be combining these orange blocks with other programming blocks to create your code.

MakeCode has a simulator that lets you hear how your code works while you write it. However, it may sound different on the actual CPX, so download and test it from time to time. Follow the Download directions on the screen, or go to the getting started guide at the link above.
Playing notes continuously on the speaker built into the CPX can cause it to get very hot! To stop the sound and let the speaker cool down without unplugging the CPX from the computer, push the "reset" button in the center of the board.

Creating the Notes and Changing the Duration

To play a repeating note, grab the play tone at Middle C for 1/2 beat block from the MUSIC menu and insert it inside a forever loop block. That's it!

The length of the note is pre-set to one-half beat. To change it, click on that space to open a drop-down menu of choices.

To create a series of notes, just grab another block from the MUSIC menu (or click on and duplicate the first block) and drag it underneath the first block until it clicks into place. Add more notes as needed to play a musical phrase over and over.

When you want a break between notes, use a rest for 1/2 beat block. As with play tone blocks, you can adjust the number of beats the rest lasts.

To mute the music in the MakeCode simulator (which can get annoying while you're trying to fix your code), click the speaker icon (shown in red in the screenshot at the top of the page).

Changing the Pitch

The play tone at block is pre-set to play the note Middle C. To change it, click on the name of the note and a piano keyboard will appear!

Click on any key to set a new note. The name of the new note will appear.

Notice that a number replaces the name of the note on the block itself. You'll learn how to use that number to vary the sound on the next page.

 

Controlling the Volume

To make the notes louder or softer, use the set volume block.

The volume is pre-set to 128. To change it, click on the number to open up a slider. Drag the slider right or left to increase or decrease the volume.

You can also type a number into the box, over the number 128.

To see how loud that sounds in real life, write a short music program and download it to your CPX. To adjust the default volume for your program, drag a set volume block into an on start block.

Controlling the Tempo

To make the entire musical phrase play faster or slower, use the set tempo block. It is pre-set to 120 bpm, which stands for beats per minute. If you type in a bigger number, the notes will speed up. Type in a smaller number to slow the notes down.

To adjust the tempo at the beginning of the program, use an on start block.

To change the tempo while the program is running, use a change tempo by 20 (bpm) block. In the example shown here, the entire musical phrase (three notes and a rest) will speed up by 20 beats per minute every time the entire forever loop repeats. Type right over the 20 to increase or decrease how much the tempo speeds up. To slow the tempo down, type in a negative number.

Be aware that even though you are changing the tempo, the notes stay the same in relation to each other. The rhythm of short and long notes will stay the same. They will just play faster or slower.

The button below takes you to a preview of the example code above. Listen for a few repetitions and notice how the notes gradually get faster and faster. To play around with the code, click "Edit" and it will open as a new project in MakeCode.

On the next page, find out how to vary the pitch, duration, tempo, and volume by changing the position of your musical glove!

This guide was first published on Apr 01, 2019. It was last updated on Mar 20, 2019.

This page (Make MakeCode Music) was last updated on Mar 20, 2019.

Text editor powered by tinymce.