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

Transcript

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.

(bouncy electronic music)

(throbbing electronic music)

Drag out a play sound until done block from the Sound menu.

Click on the dropdown, and select your favorite tune.

(rhythmic electronic music)

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.

(rhythmic electronic music)

If your song doesn't play, make sure that 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 one.

This will start playing the song quietly.

Click on this block stack.

(rhythmic electronic music)

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 one forever.

From the Sound menu, drag out the change volume by block, and type one 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.

(rhythmic electronic music)

The tune gets louder and louder, but it happens really quickly.

(rhythmic electronic music)

To change how quickly the beat reaches its loudest value, add a wait block to the code.

Test it by clicking on the volume stack, then the play music stack.

(rhythmic electronic music)

The music slowly gets louder.

(rhythmic electronic music)

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.

(rhythmic electronic music)

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 that ran at the same time.

Parallelism is an important concept computer scientists use everyday.

It means that multiple block stacks are taking place in your program at the same time.

Alright, here's the game plan.

Play a song using the play sound until done, forever, and set volume blocks.

Next, change the volume using the change volume by, forever, and wait blocks.

Finally, add broadcast, and when I receive message blocks, so your code will run before the introduction.

arrow_backward Back
Next arrow_forward
Instructions
  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.