2 Interrupts, 2 Pins, Simultaneous usage

As PaulS wrote, that code might behave weridly if an interrupt occurs during the execution of the code block inside the IF statement... For example if the signal falls after print(fall_time) but before println(rise-time-fall_time), then you'd have a fall time which is greater than rise-time! Worst, the interrupt could happen in the middle of the access to the rise_time or fall_time variable by the print function, which would result in print/println reading e.g. one byte as it was before the interrupt and another one belonging to the new time value. A disaster.
All of this won't happen if the signal timing guarantees nothing would happen during the execution of the if block. A better solution would be this (I'm writing in pseudocode what PaulS said before):

unsigned long aux_fall_time;
unsigned long aux_rise_time;

  • disable_interrupts()
  • aux_fall_time = fall_time
  • aux_rise_time = rise_time
  • enable interrupts()
  • print/ln as before, using aux_ variables instead of the other ones.

Also, I'd put a delay() as the last statement of the loop() function, to bring the ratio between int_disabled_time and int_enabled_time near zero.

HTH

(disclaimer: I'm a bit in a hurry, so errors might have slipped through the keyboard :slight_smile: