An encoder is a device which senses either a rotary or linear motion. It does this using two signal lines. The signals are generally a square wave output at 90 degrees out of phase (shifted). As the encoder rotates each switch is toggled from HIGH to LOW in sequence. The controller watches one of the lines and listens for a change in its state.
For Example: When the EncA line transitions from HIGH to LOW, the controller is interrupted from its normal program operation and runs a very small program. This function looks at the EncB signal and based on whether it is HIGH or LOW will either increment or decrement a counter. Notice, if EncA falls off the Right side of the “HIGH” it is rotating Clockwise and if it falls off the Left, it is traveling Counter Clockwise. An encoder can be used for keeping track of a counter or recording the speed and direction of rotation.

