Replace the hertz values for your piano with well-named variable to make it easier to update and modify your notes.
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: Variables replace fixed number values
By using variables throughout your loop in this project, you made it much easier to read the code now and modify it later. You almost don’t need comments to understand what is happening in the void loop. You can imagine how much easier it would be to write an automatically playing tune when you just need to identify the notes in the song and you can code more naturally with those variables.
Although all we’ve really done is rename our hertz values with a letter, this step makes a big difference when it comes to clarifying the code. Good coders are always looking for ways to make things simple and streamlined so that sneaky problems don’t show up later.