Hello I'm participating in a robotics competition and I'm using an Arduino Mega 1280. The problem I have is with my four GP2D12 IR distance sensors. They work pretty fine but since the nature of my project requires some precision, I programmed the arduino to take 10 values, calculate their mean, then calculate their Statistical Variance, then take only the values closest to the mean. All this to eliminate the peak values the sensors give from time to time, in order to get much better distance sensing.
I was very proud of my function and I went out to test the robot in the hall 8). Problem is, the time between two readings becomes too long, and meanwhile the robot has already crashed on the wall. :D
So what can I do, either to reduce the time consumed by my function, or do something to make the IRs read with a higher frequency perhaps?