I am currently writing a program where I need to run a loop that can be interrupted at any time. In this case, a series of tones are playing over and over again but should stop when one of the values from a sensor comes back as HIGH.
At the moment, I've got this:
void loop() {
while(digitalRead(ctsPin) == LOW) {
// Some code here
}
}
However, the while loop will only break when the instructions inside it have finished running. Is there a way that I can run these over and over again but stop them at any time, even if it is part-way through?
Thanks in advance.