When coming up with the design of the piano, we wanted to be able to cover one octave of naturals, the white keys on a piano, and be able to change the octave that is being played, as a standard piano has seven. As such, we would need eight pushbuttons to serve as our keys and either a seven or eight position rotary switch to be able to change the octave. LEDs were also implemented after the switches to show the user which tone is played from the buzzer.
The switch and LED series was created by putting 5V on one leg of the switch and a 220Ω resistor on the opposite corner. This resistor is then in series with the anode of the LED and a wire connecting to the ATMega328P board. Another 220Ω resistor is placed between the cathode of the LED and connected to ground. The configuration of the LED is key as current can only flow from the anode to the cathode of a diode. In the initial design, there was not a resistor between the cathode and ground. The LED would light up, but a sound would not consistently come from the buzzer. Placing the second resistor resulted in a tone being played every time the button was pressed. The LED also served to let us know when the tone would be played. The signal that the board receives from pressing the button is a square wave with either a value of 1 or 0. The LED is on when the value is 1 and off when it is 0, the speaker plays the tone during the falling edge of the wave. In other words, when the wave drops from 1 to 0, the proper tone is played. These are all plugged into pins PD0-PD7.