Stuck in an interrupt?

Delta_G wrote

If you use && then either one of them changing gets you out of that do nothing loop.

If you use &&, and read the state of RxThro you can implement a while loop with a timeout, and know which triggered the exit from the loop.

#define ledPin 13
#define RxThro 3
unsigned long Time1 = 0;
unsigned long Time2 = 0;
unsigned long pulse1 = 0;
volatile boolean failSafe = false;
boolean timeOut = false;
int FST = 15000;
boolean toggle = false;
void setup()
{
  Serial.begin(115200);
  Serial.println("begin");
  pinMode(13, OUTPUT);
  pinMode(ledPin, OUTPUT); // initialize timer1
  pinMode(RxThro, INPUT_PULLUP);
  noInterrupts();           // disable all interrupts
  TCCR1A = 0;
  TCCR1B = 0;
  TCNT1 = FST;            // preload timer 65536-16MHz/256/2Hz
  //TCCR1B |= (1 << CS12);    //
  TCCR1B |= (1 << CS11);
  // TCCR1B |= (1 << CS10);
  TIMSK1 |= (1 << TOIE1);   // enable timer overflow interrupt
  interrupts();             // enable all interrupts
}
void doCalcs()
{
  if (timeOut == true)
  {
    pulse1 = 900;
    timeOut = false;
  }
  else
  {
    TCNT1 = FST; //reset the failsafe timer
    pulse1 = Time2 - Time1;
  }
}

void getInputs()
{
  Serial.println("get inputs");
  while ((digitalRead(RxThro) == LOW) && (failSafe == false))
  {
  }
  if (digitalRead(RxThro) == LOW) // exit trigered by failsafe
    timeOut = true;
  else
    Time1 = micros();

  while ((digitalRead(RxThro) == HIGH) && (failSafe == false))
  {
  }
  if (digitalRead(RxThro) == HIGH) //exit triggered by failSafe
    timeOut = true;
  else
    Time2 = micros();
}

ISR(TIMER1_OVF_vect)        // interrupt service routine that wraps a user defined function supplied by attachInterrupt
{
  TCNT1 = FST;            // preload timer with Fail Safe Time
  failSafe = true;
  toggle = !toggle;
  digitalWrite(13, toggle);
}

void loop()
{
  failSafe == false;
  getInputs();
  doCalcs();
  Serial.println(pulse1);
}