Use micros() for timing.
volatile uint32_t risingMicros;
volatile uint32_t fallingMicros;
volatile bool fallDetected;
volatile bool riseDetected;
uint32_t timeBetweenPulses;
uint32_t pulseWidth;
void setup() {
// Attach the two interrupts.
}
void loop() {
// Deal with fallDetected and riseDetected here.
if (riseDetected) {
riseDetected = false;
timeBetweenPulses = risingMicros - fallingMicros;
if (timeBetweenPulses < pulseWidth * 2) {
// Looks like we just got the second of the double pulse.
}
}
if (fallDetected) {
fallDetected = false;
pulseWidth = fallingMicros - risingMicros;
}
}
void risingISR() {
risingMicros = micros();
riseDetected = true;
}
void fallingISR() {
fallingMicros = micros();
fallDetected = true;
}