Let me start by saying I'm a beginner. That said, I've been doing lots of "Googling" and not found anything too encouraging. Maybe some folks here can give me some ideas.
Imagine that I have a program that is synchronized with external music or video. Basically, there is a video playing on a television and I want my Arduino to activate certain devices at specific times to match specific moments in the movie. However, in the event of an "accident", I want the Arduino to do something else entirely. For instance, during the movie, suppose a fire alarm goes off. I want this to be an interrupt that tells the Arduino to turn on the lights. For whatever reason, the movie can't be turned off or paused. After the fire alarm has been cleared, I want the Arduino to keep the lights on for a few more seconds and then return to it's normal program. Only now it is perhaps minutes behind where the movie is since the program was "paused" by the interrupt while the movie was still playing.
My exact application is a little different and the time spent in the interrupt is one the order of 1 second, but for synchronization, this is still an issue. I would like to find a way to keep track of how much time is elapsed during an interrupt.
About the only thing I could come up with was to write something that works like:
interrupt triggered -> turn power to devices off, set flag, return to program
And then, before each and every block of code that activates a device, I would include a line:
if (flag == true) {wait (time); turn power on}
Where "wait" is just a while loop that makes use of millis() and since the rest of my code is activated based on the value of millis(), this should be ok. The only loss of time is the amount of time it takes to write a pin low and set a flag. Based on my research, I can safely assume this will be less than 10 microseconds.
I'd still like a better way, though. I don't want to have to copy and paste a bunch of "if statements" into my code. For reference, my board is the Mega and, using some creative switching, I will be controlling almost 500 devices, which means I would need 500 "if statements".