Use a ‘for’ loop to control where your tone starts, how high it will play, and how fast it gets there. Sounds like a siren!
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!
New Concept: 'for' loop / limited looping
Up to this point, your void loops have been stopped by only two things- uploading new code or unplugging the Code Speaker. This might have been extremely annoying on the last project as the pitch variable climbed closer and closer to a dog whistle!
In this program, you see how you can limit loops with the 'for' loop. These will give you more control over how your code runs.