Keyboard Instrument: Using a piezo and buttons to make a 4-note keyboard
This project was extremely fun cause we got to make the first project that closely related to a real life machine, and something you could play if you knew how to. Parts included the piezo, 4 buttons, and 4 total resistors of 3 strengths: 10 kilohm, 1 megohm, and 220 ohm resistors.
The build had us connect a piezo to ground and digital 8 pin. Then we had to connect four buttons to positive, with them having no resistor, 220 ohm, 10 kilohm, and 1 megohm resistor respectively. They were connected to ground in series, with there being a 10 kilohm resistor connecting all of them to the A0 analog pin, so we can read the amount of "strength" of buttons being pressed.
The book made us set up an buttons array with 6 integers, and the first one being equal to 2. I also set up a notes array with the values 262, 294, 330, and 349. These ints in Hz are equivalent to the notes mid C, D, E, and F. In loop, we compare the keyVal from A0 and see what value it is equivalent to with the amount of buttons being pressed.
Two things snagged me up while completing this project, with the first being the resistors. This is the first time where the exact strength of the resistor has mattered to making this project actually worked, and since the arduino book and kit don't give you the same resistors that go with the instructions, it took me looking up all of the resistors and marking their ohmage to be as specific as possible. Also, the syntax the book gave me for making the first value in the buttons array equal to 2 didn't work, so I had to look up the issue, and this is the line of code that worked for me: int button[6] = {2,0,0,0,0,0};




Comments
Post a Comment