Again thanks for all your help.. Your logic chart did the trick!
Its works just as it should and you are right i couldn't get my head around the OR and AND!
#define ledPin 13
#define RxThro 3
unsigned long Time1 = 0;
unsigned long Time2 = 0;
unsigned long pulse1 = 0;
volatile boolean failSafe = false;
int FST = 15000;
int B = 1;
boolean toggle = false;
void setup()
{
Serial.begin(115200);
pinMode(13, OUTPUT);
pinMode(ledPin, OUTPUT);// initialize timer1
pinMode(RxThro, INPUT);
noInterrupts(); // disable all interrupts
TCCR1A = 0;
TCCR1B = 0;
TCNT1 = FST; // preload timer 65536-16MHz/256/2Hz
TCCR1B |= (1 << CS11);
TIMSK1 |= (1 << TOIE1); // enable timer overflow interrupt
interrupts(); // enable all interrupts
}
void doCalcs()
{
if (failSafe == false)
{
TCNT1 = FST; //reset the failsafe timer
pulse1 = Time2 - Time1;
}
else
{
pulse1 = 900;
TCNT1 = FST;
}
}
void getInputs()
{
while ((digitalRead(RxThro) == LOW)&&(failSafe == false))
{
}
Time1 = micros();
while ((digitalRead(RxThro) == HIGH)&&(failSafe == false))
{
}
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);
}