7 """Class to decode mechanical rotary encoder pulses.""" 9 def __init__(self, pi, gpioA, gpioB, callback):
12 Instantiate the class with the pi and gpios connected to 13 rotary encoder contacts A and B. The common contact 14 should be connected to ground. The callback is 15 called when the rotary encoder is turned. It takes 16 one parameter which is +1 for clockwise and -1 for 34 print("pos={}".format(pos)) 38 decoder = rotary_encoder.decoder(pi, 7, 8, callback) 70 Decode the rotary encoder pulse. 72 +---------+ +---------+ 0 76 +---------+ +---------+ +----- 1 78 +---------+ +---------+ 0 82 ----+ +---------+ +---------+ 1 85 if gpio == self.
gpioA:
93 if gpio == self.
gpioA and level == 1:
96 elif gpio == self.
gpioB and level == 1:
103 Cancel the rotary encoder decoder. 109 if __name__ ==
"__main__":
114 import rotary_encoder
124 print(
"pos={}".format(pos))
int set_mode(unsigned gpio, unsigned mode)
def __init__(self, pi, gpioA, gpioB, callback)
int set_pull_up_down(unsigned gpio, unsigned pud)
def _pulse(self, gpio, level, tick)