Use back-to-back ‘for’ loops to create a sound effect you can control to sound like a laser blaster, siren, alarm, or anything else you can code up!
The code in the editor below already works. Just plug in your Code Speaker and press upload to see what it does! Tinker with it and make changes to see what each line of code controls.
Watch the videos for line-by-line explanation of how the example program works. Then you'll be ready to make some changes of your own!
Can you complete the challenge? Change the code in your code editor above. Upload your code to see the effect when you're finished. Complete a challenge? Check it off the list!
These are the new code concepts covered in this example program. To become a great coder, read through these concepts to learn new vocabulary.
New Concept: Building blocks, revisited
This program has lots of components: loops, variables and conditions. But the program can also be broken down into more easily understood groups. The void loop contains two ‘for’ loops. Each ‘for’ loop contains 4 parts: the variable, the condition, the variable change, and the actions. The actions of each ‘for’ loop are some of the most basic commands you learned: tone and delay.
Programming is about learning how to break down your problems into understandable pieces, translate those pieces to computer code, and then put the pieces back together to build your solution.