Bill,
If I understood your question correctly, when the A/D converter gives you a value of 0 that means pointing North and when you get a value of 128 that means pointing South (range is 0-255). Well, averaging a reading equal to 1 with a reading equal to 255 won't work. These two readings are close to 0 (North) but if you average then out you will get a value of 128 which is pointing South, the opposite direction.
This problem is harder than what it looks, so don't think you are asking an idiot question. Right now I can't think of a way of averaging these two values using simple algebra or a simple algorithm. However, by using trigonometry these kinds of problems are very easy to do. Unfortunately, PBP does not offer too many trigonometric functions except sine and cosine.
My suggestion,
- Treat each reading as an angle (that's what they really are).
- Use the PBP cosine function to add the X components of the angles (they can be as many as you want).
- Use the PBP sine function to add the Y components of the angles.
- Determine the new value of the new angle (new reading)
I am very sorry if I confused you more than what I helped you, but if you need help let me know.
Robert
Bookmarks