Variable Note Piano

Replace the hertz values for your piano with well-named variable to make it easier to update and modify your notes.

Code

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.

Walkthrough Videos

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!

Challenges

Can you complete the challenge? Change the code in your code editor above. Upload your code to see the effect when you're finished. Complete a challenge? Check it off the list!

Concepts

These are the new code concepts covered in this example program. To become a great coder, read through these concepts to learn new vocabulary.

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.

Quiz

If you're having trouble, try to run an experimental program or look at the example code to help you find the answer.

1. When picking a variable name, it's a good idea to pick a name that is....



2. Based on this example program, how would you define 'variable'?