For this week’s assignment, we wanted to design a mini piano using switch buttons. Our goal was to make each button have a different note so that when users play the piano they can recreate the sound from the “Happy Birthday” song. We also added a potentiometer to our circuit so that we could regulate the volume of the sound.
Image of notes:
To build the circuit we added switch buttons and resistors and connected the wires to the pins. We downloaded pitches from examples→toneKeyboard, each switch button had its own musical note from the song(C5, B4, A4, G4, D5). We struggled a bit with adding potentiometer and piezo buzzer to our circuit with piano buttons, however we managed to solve the problems and understand the process.
At the beginning we initialized the piano buttons, buzzer and potentiometer. Next, we went on to add the code for the buzzer and potentiometer. We wrote code to read the input on the analog pin and turn the piezo buzzer on and off. Also, we set a tone for each button and activated it. To improve this work, next time we can add more buttons and play new songs:)
Final code:
Link to GitHub
Final result:
IMG_6078