
151Chapter 8: Rotary Encoder Control
Next, we have our void loop, in which we need to accomplish
two key things. First, we need to create a system for comparing
the two square waves coming from the DT and the CLK pins.
Thankfully, as we saw a few chapters ago, square waves are
nothing more than a string of binary 1s and 0s, highs and lows. In
order to read which direction the encoder is rotating, as well as
how many times it has ticked—indicating how far the encoder has
rotated—all we need to do is monitor the state of both pins using
the digitalRead() command.
We first use the digitalRead() command to check the status
of our CLK pin. (If that ...