Using the same hardware setup from the SIMPLE PIANO project, we can turn our RaspberrySTEM into a mini-keyboard. We will modify the code so that each time you press one of the buttons on the RaspberrySTEM, the corresponding note plays for as long as the button is held:
Step #1: Build the circuit.
Your breadboard should still have the circuit we wired in the MANY BUTTONS project. As a reminder, here is what it should look like:
Step #2: Write the code.
The main change in the code for this project is -- after detecting a button press -- to monitor the button state to determine if continues to be pressed, and if so, continue to play the note.
Here is what the code should look like: