A rotary encoder has a slit disc with equally spaced grid markings attached to its rotating shaft, and a fixed slit with the same spacing markings fixed to the main body opposite it. A light-emitting element (LED) and a phototransistor are positioned on either side of these two slits. As the rotating shaft rotates, the light emitted from the light-emitting element is blocked by one slit pitch at a time, causing it to blink on and off a number of times proportional to the amount of rotation. This blinking is extracted as an electrical signal by the phototransistor, and the waveform is shaped into a square wave, which becomes the encoder's output signal. Generally, this output signal is a two-phase signal with phases adjusted so that they are 1/4 pitch apart. When the direction of rotation reverses, this phase also reverses, and by combining it with a reversible counter that has a direction discrimination circuit, it is possible to add or subtract the amount of rotation.