Let the code ‘choose’ which tone to play next on your speaker. You set the speed and the range, then settle in for a wild ride!
The code in the editor below already works Just plug in your Code Piano 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: Random
The computer ‘makes a choice’ in this program about which tones it plays. Using this function can make your code do some things that are unpredictable, even to you, the programmer! This same logic is how some code in the real world, like slot machines, makes a random choice.
You can replace most number in code with functions like ‘random’. The important thing to remember is the syntax, or punctuation, that is required for the function. Use the purple cards in your kit as a reference for the syntax that each function requires.