In this project, we used a few resistors, switches and a Piezo speaker to create a simple instrument. Using the analog input, we can read the number of switches we use. We make a parallel circuit connected to Analog 0 on the Arduino, which we can then use the different resistors to determine the voltage that will be changing the frequency/note that the different switches will play through the Piezo.
When it comes to the code, we determine the notes to play by creating an array, to store the different values of voltage, before the setup of the code. You then begin a serial communication with the computer. In the loop you set up the code to read the A0 Input. Using an if/else statement, we can assign different values for the different tones. After each if statement, you call the tone function, and Arduino Uno will tell what notes to play.