i am trying to compare the elements of two arrays before the code goes on to the next sequence. The elements of note[x] are filled with the note values of a song. and i want to be able to input values from a midi controller into learn[x]. how can i compare array learn[ ] to array note[ ] before the showsequence(); is incremented?
const int x = 100;
int note[x];
int learn[x];
int largestindex = 0;
int learnindex=0;
void showsequence();
void readsequnce();
const int PLAY = 1;
const int TRYAGIN = 2;
int state=0;
void loop() {
if (state == PLAY) {
showsequence();
readsequnce();
}
else if (state == TRYAGIN) {
incorrect();
}
MIDI.read();
}
void MyHandleNoteOn(byte channel, byte pitch, byte velocity) {
learn[learnindex]=pitch;
learnindex++;
}
void showsequence() {
//Add a new index to the end of the songseq
SongSeq[largestindex];
largestindex++;
//loop through the songseq
for (int index = 0; index < largestindex; index++) {
SongSeq[index]();
}
}
void readsequnce() {
static uint16_t nextkey;
bool mademistake = false;
nextkey=0;
learnindex=0;
if (array_cmp(learn, note, largestindex, largestindex) == true){
// do this if they are equal
lcd.setCursor(16, 2);
lcd.print("True");
}else{
// do this if they are different
lcd.setCursor(16, 2);
lcd.print("False");
}
}
boolean array_cmp(int *a, int *b, int len_a, int len_b){
int n;
// if their lengths are different, return false
if (len_a != len_b) return false;
// test each element to be the same. if not, return false
for (n=0;n<len_a;n++) if (a[n]!=b[n]) return false;
//ok, if we have not returned yet, they are equal :)
return true;
}