While working through a few queries about the rotary encoder library, it became evident that it would help to have a better test application to diagnose wiring issues.
I’ve committed a better version of
rotary_test.py that writes out a comprehensive table of state information, updated whenever anything changes.
The output looks like this:
The values in the table are defined as follows:
|A||Raw value of input A|
|B||Raw value of input B|
|STATE||Quadrature state 0,1,3,2|
|SEQ||Ordinal sequence 0,1,2,3|
|DELTA||Net change in position|
|SWITCH||Push-button switch state|
One small note on the implementation: although there are library calls to directly fetch each of the values in the table, the test program only calls the library to retrieve
SWITCH, and then derives the other values from
STATE. I did this to make sure each column is generated from the same inputs. If instead I made separate library calls to fetch each column value, it is quite likely that the inputs would change while generating a row of this table, producing inconsistent and confusing results.