int notes[]= {262, 294,330,349 }; // frequencies in Hz for do re mi fa fa
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
int keyVal = analogRead(A0);
Serial.println(keyVal);
if(keyVal >= 6 && keyVal<=9) { //pushing button 1
tone(8,notes[0]);
} else if(keyVal >= 510 && keyVal<=513) { //pushing button 2
tone(8,notes[1]);
}else if(keyVal >= 1000 && keyVal<= 1003) { //pushing button 3
tone(8,notes[2]);
} else if(keyVal == 1023) { //pushing button 4
tone(8,notes[3]);
}
else { //pushing nothing
noTone(8);
}
}
As I said before, I would add, for example, the note "sol" pushing for example button 3 and button 4 at the same time, but the value shown on the screen (thanks to the Serial.println) is the same of that of button 3, so it's impossible for me to associate a new value to the frequency of the note sol.
The schematic is in the attachment, if it's what you meant before.
