How to make a graphite arduino piano?

Hey frnds! I got inspired by this project:    https://www.instructables.com/id/Graphite-Controlled-Step-Sequencer/      and a new project came in my mind which will use arduino but i'm not good at programming. As in the above mentioned project the graphite worked as a variable resistor. Is there a way to use this resistor with arduino to play different tones at different resistivity from the "pitches.h library". I know there can be. So plz if anyone know kindly give the program.

sort by: active | newest | oldest
bwrussell2 years ago

You would do it just the same as using a variable resistor (potentiometer). The strip will provide different voltages along it's length. Simply divide the input range up into the number of pitches you want and assign a pitch to each segment. When the voltage falls into a certain range have the pitch assigned play.

If you use the resources at www.Arduino.cc and take a shot at writing the program I can help you get it right.

1101Snehil (author)  bwrussell2 years ago

Thnxx bwrussell but i dont know the programming of arduino quite well. can uu plz write the program for me.

Sounds like the perfect opportunity to learn. Again, I will help you but I'm not going to just write it for you.
1101Snehil (author)  bwrussell2 years ago

sorry to rply so late. Ok i will start writing the cpde today. Can you atleast tell how to divide the board in different sections in void setup. I defined two variable before it.

Res = 20 /max variant pf the sheet.

Div = 10 /no of divisions to be made

assuming you have the strip hooked up across 5v, the analog input will be from 0 to 1023. Divide by the 10 keys you need. This works out to 102.3 steps per division but you'll want to round up to 103. Using integers (int) as your variable type, if you divide the input from the pot at any given time by 103 it will return 0-9 which gives you 10 positions.

1101Snehil (author)  bwrussell2 years ago

Ok i wrote the sketch upto what you said but how to check if the value is between a certain two consecutive numbers. is it something like if and then comaand. At last which tones from the tones.h library should i choose. there are many. i think the ones which can create some sort of music like a real piano. but which ones are they.

Yes, you can use a chain of If.. Else If to get a reaction for each number but there is a more elegant solution. It's called a switch case. Since you're input is being cleaned up into nice single values (0-9) the switch case is perfect for your needs. It operates much like If (x = y) then, else if (x=z) then ... etc but a little cleaner.

You can read about and see examples of both Else If and Switch Case on the reference page of the arduino website. Look under the section called Control Structures. Take a shot setting it up using either one of those. If you get stumped let me know.

I think a much simpler version of this could be achieve using a makey makey.