I would like to change the delay() into a nonblocking function in the code below. I've implemented it (a part of a tutorial from arduino.cc) in my code, but the delay() is blocking the rest of my code. Can anyone help me to change this?
void speelMelodie(int melodie){
if(melodie == 1){
for (int thisNote = 0; thisNote < 8; thisNote++) {
int noteDuration = 1000 / noteDurations1[thisNote];
tone(speaker, melody1[thisNote], noteDuration);
int pauseBetweenNotes = noteDuration * 1.30;
delay(pauseBetweenNotes); // <-- this one has to be changed
noTone(speaker);
}
}
else if (melodie == 2) {
// the same part as previous part (for loop)
}
else if (melodie == 3) {
// the same part as previous part (for loop)
}
}