In the sample program off of the lynxmotion website we are trying to understand this part of the code.
for temp = 0 to 10
adin 18, filter(temp)
next
ir_right = 0
for temp = 0 to 10
ir_right = ir_right + filter(temp)
next
ir_right = ir_right / 85
We are trying to figure out what exactly the temp variable does and what 0 to 10 does for the sensor. We figured out that if you change the 85 so the sensor sees different distances. Our main question is whether or not the 0 to 10 deals with time or something else/
That part of the program averages out 10 readings. It’s job is to help remove any spurious readings the sensor might get. The first for next loop fills the array with 10 readings. The second for next loop adds them together. I’m not sure why the total is divided by 85 and not 10. If I wrote it, I don’t remember…
Dividing the total by 10 would indeed give you the average, but that also makes the robot react to walls much before it really needed to. After some tinkering, 85 seemed to give the best results in that the robot would turn gently away from obstacles several inches away as opposed to abruptly turning in response to an object 2 feet out.