Johan_Ha:
case 0: // Wait for like half a second to check the distance again
if micros() > next_event
{
I noticed you commenting very effectively about English usage in another recent Thread so I say this with a little reluctance.
I wonder if use of the words "wait for" may give the wrong impression (i.e. suggest the use of use delay() ) whereas I suspect you meant "when a half second has elapsed"
And (nothing to do with English) the code should check time using subtraction to avoid problems when micros() rolls over - like this (just the same as one would do with millis()
if (micros() - prevEventMicros >= TTT) { // where TTT is the desired interval
...R