Im currently building a robot that uses a ultrasonic sensor to gather data (distance). I have a dc motor spin and while that is happening the ultrasonic sensor is gathering distance data. The code that I am running is an if/else if statement based on the data I have, the problem is that it uses the last bit of data it receives from the ultrasonic sensor. I want the if/else if statements to be based on all the data it receives and not just the last, one single piece of data. Is there a way that I make it so that the if/else statements are based on a group of data instead of a single piece of data? Thanks so much!
Arrays come to mind. Store e.g. successive measurements in an array, do a calculation (maybe average or so) and base the if condition on the calculated value.