I have four IR encoders hooked up to my A2D pins on an ooPIC - R. The IR encoders are facing the inside of a wheel that has a reflective/nonreflective (white/black) pattern on them.
I am currently reading the pins in 10 bit mode, so I get values ranging from 0 to 1220 or something like that.
My problem is that I do not know how to write the code so that every time the IR encoder changes from either white to black, or black to white, it adds one to an interger that is used to count how many clicks the wheel has made.
The main issue is that the A2D level for the encoder never stays the same. It always fluctuates by about +/- 10 digits while standing still. And also, when over the white part of the wheel, the encoder reads a level or 900 +/- 100, and when over the dark part, reads about 300 +/- 100.
So how would I even start to write a code that says: When IRLevel goes from high (around 900) to low (around 300), add one click, and v.v.
Or even simpler, add one click to the count when IRLevel changes by 400?