Hello there,
I’ve got 3 of these sensor and I’m pretty happy about it. But I can’t figure out how to return the sensor working duration time if the threshold is triggered. I already tried the millis() function but all my attempts are failed. Here is the related code:
boolean isSensor2AboveThreshold() {
return sensor2.readRangeSingleMillimeters() > sensor2_threshold;
}
void loop() {
tcaselect(2);
// Serial.print(sensor2.readRangeSingleMillimeters());
switch (current_state) {
case THRESHOLD_ABOVE:
if (isSensor2AboveThreshold()) {
//elapsed_time = millis() - start_time;
Serial.print("threshold_ABOVE");
} else {
//counter_below_ms = counter_above_ms;
current_state = THRESHOLD_BELOW;
//final_ms = counter_above_ms - counter_below_ms;
}
//break;
case THRESHOLD_BELOW:
if (!isSensor2AboveThreshold()) {
//counter_below_ms = millis();
Serial.print("threshold_below");
}
/*else{
}*/
// break;
} //end of switch(current_state)
Serial.print("The blue ball is held up for: ");
Serial.print(elapsed_time);
Serial.print(" ms");
} //////////////////////////// end of loop
thanks in advance.