Skip to content

Please update your browser

Your browser version is not supported by this site. CS First may not work properly. Learn more

4. Pump Up The Volume


In this video, you will add a tune that gets louder throughout your commercial until it’s booming. By letting the beat build, you will capture how truly inspiring it is to use your fitness gadget.

Start by playing the music. Click on the sounds tab and select a song. Drag out a “play sound until done” block from the sound menu. Click on the dropdown, and select your favorite tune. Press the “stop” sign to stop the song. Try out a few different tunes until you find one you like! To ensure that your tune doesn’t ever stop playing, from the “control” menu, place a “forever” loop around the “play sound until done” block. That makes your song play over and over, forever. Try it out. If your song doesn’t play, make sure you’re using a “play sound until done” block, not a “play sound” block. Set the volume to start at its lowest setting.

From the “sound” menu, drag a “set volume” block into the scripts area, and set its value to 1. This will start playing the song quietly. Click on this block stack. It will play very quietly-- you might not be able to hear it. Click the stop sign to stop it.

Next, add volume control. The volume needs to get louder as the song plays, so it needs its own block stack. To make the song get louder over time, change the volume by 1 forever. From the sound menu, drag out the “change volume by” block, and type 1 in the value space. Then, place a “forever” loop around it.

Try it out. Click on the “play sound until done” block stack, then the “change volume” block stack. The tune gets louder and louder, but it happens really quickly.

To change how quickly the beat reaches its loudest volume, add a “wait” block to the code. Test it by clicking on the volume stack, then the play music stack. The music slowly gets louder! Tinker with the wait time to slow down or speed up the volume change.

From the “events” menu, place a “broadcast” block before the “broadcast and wait” block that introduces the fitness gadget. That way, the song will play at the beginning of your commercial. Use the “broadcast” block rather than the “broadcast and wait” block - the “broadcast and wait” block will wait until the response to the message is finished before running any more of the program, and since the response uses a “forever” loop, the rest of the program would never run!

Click on the broadcast dropdown menu and select “new message.” Type “Pump Up The Volume” as the value. Both the music and volume stacks need to receive the “Pump Up The Volume” message. From the “events” menu, place the “when I receive” block above the music-playing block stack. Click the dropdown to make sure it reads “Pump Up The Volume.” Follow these same steps for the volume block stack.

Click on the flag to try it out! That sounds amazing! Before, you had to click on each block stack separately to make the song play and get louder over time. Broadcasting the same message to different block stacks accomplished something truly magical: parallelism – two different pieces of code ran at the same time!

Parallelism is an important concept computer scientists use every day. It means that multiple block stacks are taking place in your program at the same time.

Here’s the game plan: Play a song using the “play sound until done”, “forever” and “set volume” blocks.

Change the volume using the “change volume by”, “forever” and “wait” blocks.

Add “broadcast” and “when I receive message” blocks, so your code will run before the introduction.

arrow_backward Back
Next arrow_forward
  1. Play a song using the "play sound until done", "forever" and "set volume" blocks.
  2. Change the volume using the "change volume by", "forever" and "wait" blocks.
  3. Add "broadcast" and "when I receive message" blocks, so your code will run before the introduction.