How to check if a value exists in an array

Sorry you’ve been having problems. I meant to add something yesterday but life was rather busy then.
As has been stated I’d start with adding the use_real_time inside the osc receiving loop.
There are various ways to deal with ranges of input. You can use the ruby include? method (although ruby per-se is not formally supported I find it works OK.) Similarly the ruby case structure is something I’ve also used in such situations. Ive also used multiple if…elsif… statements.
The ultrasonic sensors are not particularly responsive. You will find things are much better if you invest in a ToF (Time of Flight) sensor