Image may be NSFW.
Clik here to view.
[hw640] has put together a well written and detail packed explanation of how to interface with a digital rotary switch. These digital opto encoders have just two outputs with four possible logic levels (00, 10, 11, 01). The relative position of the switch is insignificant but the direction of rotation is what matters.
The short and dirty: Each of the switch’s 2 output pins is attached to a pin change interrupt on the microcontroller. Every time the switch moves it generates either a rising edge or a falling edge on one of the two pins; both edges cause an interrupt. By checking which pin caused the interrupt, then comparing the logic levels of the two pins after that interrupt, we can determine the direction the switch was rotated.
Although this explanation uses a PIC and code written in PicBasic Pro the concepts are discussed in the abstract and would easily be adapted to an AVR or another microcontroller of your choice.
Posted in misc hacks, peripherals hacks Image may be NSFW.
Clik here to view.

Clik here to view.
