Hi,
What you are doing is looking at the output that a quadrature encoder would supply.
You need to poll input A,
when it goes HIGH,
you poll input B,
if it is LOW then you must be going forwards, because it hasn't gone HIGH yet.
if it is HIGH, then you must be going backwards, because it must have gone HIGH before A went HIGH.
You need to detect the change in state of A from LOW to HIGH, when it does then check level of B.
Tom... ![]()
Hope it helps, I'm off to bed...