A rotary encoder is equipped with a slit disk that has evenly spaced grid markings engraved on its rotating axis, and a fixed slit with the same spacing is secured to the main body. Between these two slits, a light-emitting element (light-emitting diode) and a light-receiving element (phototransistor) are installed. The light emitted from the light-emitting element is interrupted by the rotation of the axis, creating a series of light and dark signals corresponding to each pitch of the slit, which is proportional to the amount of rotation. This light and dark pattern is captured by the light-receiving element as an electrical signal, which is then shaped into a rectangular wave, forming the encoder's output signal. Generally, this output signal is a two-phase signal with a phase adjusted to be 1/4 pitch apart, and when the direction of rotation is reversed, this phase also reverses. By combining this with a reversible counter that has a direction discrimination circuit, it is possible to perform addition and subtraction of the rotation amount.