Replace the note delay with a variable so you can easily speed up or slow down the pace of your song as you ‘tune it in’.
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: Reducing repetition
Whenever a programmer finds themselves repeating something over and over again, it’s time to look for a new way of doing things. If you’re trying to write a song and you have to change every single delay each time you have a ‘test listen’ to see if the song sounds right, it’s time to use variables. Here, the variable allows you to very easily change the speed of the song and reduces the amount of typing you have to do as you tweak your code.