Why An optical shaft encoder converts mechanical rotation into electrical pulses. A slotted or patterned disc is mounted on the shaft and spins between an LED and a phototransistor, so the light beam is alternately passed and blocked as the shaft turns. Counting those pulses gives rotation amount, and a second offset track (quadrature) tells the circuit which direction the shaft is turning. This is how VFO tuning knobs on modern radios work, with no electrical contact to wear out.
Watch out Measuring light strength with an A/D converter describes an optical power meter or light sensor, not an encoder, which cares about interruption of the beam over time rather than its intensity.
Encoder = slotted wheel chopping a light beam: chop, chop, chop = count the turns.