simulate this circuit – Schematic created using CircuitLab
Figure 1. 2-bit rotary encoder waveforms.
A rotary encoder works by outputting a pair of quadrature (90° offset) pulse trains. These are used to run an up-down counter to keep track of the position. A suitable control algorithm would be as follows:
- Track the current state of 'A'. If the state changes to 'high' then:
- Look at input 'B'. If 'B' is low then count up. If 'B' is high then count down.
To get an encoder to do what you want you will need to add some logic to see if it's counting up (clockwise) or down (anti-clockwise) and pass the pulses to the appropriate button input. You won't need to keep track of the actual count.