Automatically speed up your song each time it plays through using a speed variable. Pretty soon, it will play too fast to hear anything more than a ‘blip’!
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: Changing variable values
Up until now, variables have been a replacement for numbers in your program. In this project, you see a new way to use variables as values that change over time! When you use variables this way, your code is updating itself. This is a big advantage of using variables. As a programmer, you can build the ‘system’ and put the rules in place, then the code can run and change itself!
Note on integers: You may remember from previous lessons and videos that the integer (int) type variable can only be a whole number. As the note variable divides by 2 each time, it will eventually include some decimals, like the number 37.5. Because we used an integer variable, the program will ignore that decimal and instead see the number as 37.
Eventually, the variable will be so small that dividing it by 2 again makes the variable have a value less than 0. An integer variable will ignore the decimal, so the variable will get ‘stuck’ at 0 and can’t be divided anymore.