Hello I'm very new to c++ and I am currently working on a project that requires a block of code to be executed when all conditions are met:
Condition 1: the object must be detected within 80cm or less.
Condition 2: the object must be within that 0-80cm range for 5 or more seconds.
Condition 3: when both condition 1 and 2 are met, when the object is no longer in range (more than 80cm), execute block of code.
I was recommended using a timer library for this, but a simpler idea I had was to take advantage of the serial monitor displaying all the distances each second.
Is there a way to program this:
If the next 5 or more distances (consecutively) that are recorded each second are within 0-80cm
Confirm that the block of code can be executed. (boolean maybe? idk)
Execute code when distance recorded is greater than 80cm.