Keyboard Instrument with Song Detection

I am interested in taking the Keyboard instrument created from the project book and turning it into an escape room lock, where when you play a song it will unlock something. I am having trouble figuring out how to write logic that will track a sequence of inputs from the touch keys because they aren't discrete but continuous when pressed down. Can someone help me?

Start by posting the code that you want to base the changes on. Most members, including me, will have no idea of the project book and what it contains

The easier you make it to read and copy the code the more likely it is that you will get help

Please follow the advice given in the link below when posting code , use code tags and post the code here

int notes[] = {262,294,330,349,392};

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);


if(keyVal == 1023){
  tone(8, notes[0]);
}
else if(keyVal >= 900 &&keyVal <= 1010){
  tone(8, notes[1]);
}
else if(keyVal >= 605 && keyVal <= 700){
  tone(8, notes[2]);
}
else if(keyVal >= 500 && keyVal <= 605){
  tone(8, notes[3]);
}
else if(keyVal >= 5 && keyVal <= 20){
  tone(8, notes[4]);
}
else{
  noTone(8);
}



Thank you (and for correcting it !)

Here is my code. I have a set up on my hardware that plays those 5 notes when the buttons are pressed. This code works properly now. What I'd like to add is a logic that records the sequence the buttons are pressed and then checks it against an pre-defined array (another song).

If you save the value of i, the index to the array of notes, in a second array each time a note is played then you will be able to test the order they were played in

Could you explain this a bit more?

When I read the serial output of keyVal it is continuously reading either 0 or a value. If I press and hold the button it reads the value out many times. How can I sequence it so it only records a single instance of each note as it is played?

Only play the note when the value of keyVal becomes something other than zero rather than when it is something other than zero

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.