A rotary encoder is a device that senses the rotation and direction of an attached knob. It works by having 2 internal contacts that make and break a circuit as the knob is turned. As you turn the knob you can feel it "click" indicating that one position has been rotated. If the internal contacts were originally HIGH (or making the circuit) after a single click, they would now both be LOW (breaking the circuit). With a simple bit of logic, you can work out the direction of the rotation!