Skip to content

Please update your browser

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

3. Add a Repeating Sound


This screencast will show you how to let your DJ control the frequency of a repeating sound using the scrollbars on the screen. DJs mix short sounds, called samples, of other music or sounds into the underlying track to create a new song. As the DJ drags the scrollbar, the sound of the sample speeds up or slows down.

First, choose the sample sound that you want to mix into your song. Just like with the musical loop track, you want it to play forever once the flag is clicked. Go ahead and add the blocks needed to play the sound forever and to start running the code when the flag is clicked. This block stack probably looks quite familiar to you by now. There is the starting event block "when flag clicked" that will start running this stack when the flag is clicked...and since there are two of these, both the "meow" sound and the "techno" sound will start when the flag is clicked.

This example shows a forever loop and the “play sound” block that will make the meow sound keep playing over and over again once it is started.

Try out the code. That doesn’t sound so good, does it? The meow is playing over and over again so quickly, no single meow ever finishes. Try adding a “wait” block to space out the sound more. Usually, the best way to solve a problem like this one is to keep trying blocks and testing the code until you find the fix that works for your project.

That's better! But what if you want to speed up or slow down the “meow” sound? You can change the “1” second to any number you 4. That works, but it would be too hard to keep changing that number while the user is mixing in even more sounds. Computer scientists like you often build tools others will use. So, they need to keep the users of their programs in mind when they build. For example, the computer scientists who built the DJ mixing tools you saw in today’s starting screencast had to think about making a tool for the DJs that was both powerful and easy to use. You want this tool to be as easy to use as possible for future contestants in your “battle of the DJs.”

It is too hard to change the number to control the speed of the sound and press the spacebar to make the sound play at the same time. In the next screencast, you'll learn how to make a sliding control to adjust the speed of your repeating sound.

Now, it's your turn. Add a sound that will play repeatedly once the green flag is clicked.

Remember, if you get stuck, you can always ask a neighbor for help or put up your sticky to get the attention of your CS First Guru.

arrow_backward Back
Next arrow_forward
  1. Choose a new sample sound to mix over the background track.
  2. Program the sample sound to play continuously.
  3. Add a "wait" block to slow down the speed of the sample.