Hello,
I've recently acquired a starter kit, and am currently working on Project 07 - Keyboard Instrument. I can play notes individually and it works fine, but when I press two buttons simultaneously, analogRead returns the value associated with only one of them (the one whose associated "if" statement appears first in my code). I don't know exactly what values I should get, but the Projects Book does state that I should get a unique value, different from the ones I get when I press only one button at a time.
It would be no use to post a schematic diagram for my system, since I believe (perhaps wrongly) that I've built my circuit exactly how the book told me to. So here's a photo from the book:
And just for comparison, here's the book's illustration:
And a photo of my circuit:
My code:
int notes[6] = {262, 294, 330, 349};
void setup() {
Serial.begin(9600);
}
void loop() {
int keyVal = analogRead(A0);
Serial.println(keyVal);
if(keyVal >= 1015){
tone(8, notes[0]);
}
else if(keyVal >= 990 && keyVal <= 1010){
tone(8, notes[1]);
}
else if(keyVal >= 490 && keyVal <= 510){
tone(8, notes[2]);
}
else if(keyVal >= 15 && keyVal <= 25){
tone(8, notes[3]);
}
else{
noTone(8);
}
}
It differs from the code in the book only slightly; I had to adjust the values in the "if" statements just a little. But like I said, the keyboard works just fine when I press only one button at a time, so if there's a problem I don't think it comes from the code.
I know I shouldn't expect to hear a new note when I press two buttons at once, since my code only takes into consideration the analog values for individual buttons; like I said above, what concerns me is what I see in the serial monitor. I only ever see 5 values: around 1023 when I press the first button, around 1000 for the second button, around 500 for the third, around 20 for the fourth, and around 10 when I press no button (which I think indicates my circuit is noisy?).
Any help appreciated.


