Start building a piano by getting a single key to trigger a note.
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: Inputs to your code
Up to this point, your code has run automatically after you hit the ‘Upload’ button. Only you, the programmer, had the power to make changes by digging into your code to write an update. With the ‘if’ statement, you are now allowing your code to be updated by an interaction with the outside world. The code is looking for input from the button and ‘making a decision’ based on that input.
If you think about most computer programs you interact with each day, whether an app on a phone or a setting for the microwave, they require user input to start working, so this concept of ‘listening’ for an input and the making a decision based on it is an important one.
1. The two main parts of an 'if' statement, according to the code walkthrough video, are:
2. Can you have an 'if' statement without an 'else' statement?
3. Can you have an 'else' statement without an 'if' statement?