unsigned long time0 = 0;
unsigned long time1 = 0;
int threshold = 350;
void setup() {
Serial.begin(115200);
}
void loop() {
if (analogRead(A0) > threshold) {
time0 = micros();
}
if (analogRead(A1) > threshold) {
time1 = micros();
}
if (time0 && time1) {
if (time1 > time0) // time0 was first
Serial.println(time1 - time0);
else // time1 was first
Serial.println(time0 - time1);
time0 = 0; time1 = 0; // reset times
delay(250); // avoid ringing
}
}