So you want something like this?
const byte LedPin = 8;
const byte SwinPin = 3;
volatile boolean StartSignal = false;
unsigned long MaxStartTime = 5000; // StartSignal must be set within 5 seconds
unsigned long StartTime;
void setup() {
pinMode(LedPin, OUTPUT);
pinMode(SwinPin, OUTPUT);
// initialize timer1
cli(); // disable all interrupts
TCCR3A = 0; // Clean the registers
TCCR3B = (1 << CS12) ; // Prescaler 1024
TIMSK3 |= (1 << TOIE3); // enable timer overflow interrupt
sei(); // enable all interrupts
StartTime = millis();
}
ISR(TIMER3_OVF_vect) { // interrupt service routine
digitalWrite(LedPin, !digitalRead(LedPin));
StartSignal = true;
}
void loop() {
static boolean running = false;
// Wait for start signal from ISR
if (!running) {
if (StartSignal) {
running = true;
} else {
if (millis() - StartTime >= MaxStartTime) {
// ERROR: StartSignal did not get set in time
}
}
return;
} //end if (!runing)
// RUNNING. Do the stuff
}