
72 Chapter 4 • Reading Sensors
count increases, while turning in the other, the count decreases.This count is rela-
tive to the starting position of the sensor.When you initialize the sensor, its count
is set to zero, and you can reset it again in the code, if necessary.
By counting rotations, you can easily measure position and speed.When con-
nected to the wheels of your robot (or to some gearing that moves them), you
can deduce the traveled distance from the number of turns and the circumference
of the wheel.Then you can convert the distance into speed, if you want, dividing
it by the elapsed time. In fact, the basic equation for distance is:
distance ...