I appear to get two events for every click of rotation.
I am using python to debounce the switch:
Code: Select all
from gpiozero import Button
import time
input_A = Button( 18, bounce_time = .1)
input_B = Button( 23, bounce_time = .1)
old_a = True
old_b = True
def get_encoder_turn():
# return -1, 0, or +1
global old_a, old_b
result = 0
new_a = input_A.is_pressed
new_b = input_B.is_pressed
if new_a != old_a or new_b != old_b :
if old_a == 0 and new_a == 1 :
result = (old_b * 2 - 1)
elif old_b == 0 and new_b == 1 :
result = -(old_a * 2 - 1)
old_a, old_b = new_a, new_b
time.sleep(0.001)
return result
x = 0
while True:
change = get_encoder_turn()
if change != 0 :
x = x + change
print(x)