8-Button Piano – The Big Picture

The principal goal of our project was to design and build an 8-button piano & music player – two different implementations of the same circuit. As a piano, our circuit utilizes the attached buzzer to generate tones C6 through C7; this was achieved through the use and development of an interrupt driven system. Once the button is pressed, the corresponding LED illuminates and its given tone plays through the buzzer. As a music player we utilized the same buttons, instead once the button is pressed and the LED is lit, the buzzer begins to play a pre-programmed song. These tunes utilize the same tone generation in the piano. We were able to accomplish both programs for our circuit by writing and debugging in the C programming language within Atmel Studio 7.0.

 

 

Furthermore, we continued to use the Xplained Mini ATMega328P microcontroller from the previous labs in our final project implementation. We faced several setbacks when implementing our planned design including, but not limited to, configuring the GPIO pins to accept an input from the buttons, eliminating the rotary switch, and generating a tone from the connected buzzer. Nevertheless, we were able to overcome these hurdles and implement our design as intended with only small modifications to the circuit and code.

8-Button Piano – Interrupt Driven Code

Our 8-Button Piano is driven purely by interrupts. Utilizing the in-class example for button handling, we configured all 8 of our buttons as input using the GPIO ports available on the ATMega328P Xplained Mini microcontroller. In order to achieve a level of attainable modularity with our design, we utilized predefined macros to indicate the data direction register, port, and pin numbers for each of our buttons.  Continue reading 8-Button Piano – Interrupt Driven Code

8-Button Piano – Schematics

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.