Here is an example of wiring a Rotary Encoder to an inexpensive and easy to use Microcontroller.
The Rotary Encoder is from Zapp Automation, and the controller is the STM 32NUCLEO L476RG
The controller was programmed using the free online compiler at mbed.org
The STM controller board is powered from the pc USB connection, the board in turn powers the encoder. Using three inputs configured to generate interrupts, any output change from the encoder causes the controller to respond using 'interrupt handler' routines. In this way the controller interrupt mechanism keeps track of the rotary encoder position in two integers : 'turns' and 'angle'. The number of whole rotations is kept in 'turns', this value becomes more positive for anticlockwise and more negative for clockwise rotations. Similarly, 'angle' stores a number corresponding to shaft angular position at any time.
Using the interrupt mechanism makes life much easier for the programmer. The main user programme merely needs to refer to 'turns' and 'angle' to know all there is to know of shaft rotation.
I have published this programme on the mbed site here.
Update April 2018 - fitted encoder to Challenger lathe, wired up to PC running LinuxCNC, waiting for me to fit leadscrews and stuff. Looks very promising, LinuxCNC reads encoder, hope to be screw-cutting with this soon!