Skip to content

Instantly share code, notes, and snippets.

@codelectron
Last active December 14, 2024 14:29
Show Gist options
  • Select an option

  • Save codelectron/aa35d514ecc2a43c5b57aa1912f8530c to your computer and use it in GitHub Desktop.

Select an option

Save codelectron/aa35d514ecc2a43c5b57aa1912f8530c to your computer and use it in GitHub Desktop.
from RPi import GPIO
from time import sleep
clk = 17
dt = 18
GPIO.setmode(GPIO.BCM)
GPIO.setup(clk, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(dt, GPIO.IN, pull_up_down=GPIO.PUD_UP)
counter = 0
clkLastState = GPIO.input(clk)
try:
while True:
clkState = GPIO.input(clk)
if clkState != clkLastState:
dtState = GPIO.input(dt)
if dtState != clkState:
counter += 1
else:
counter -= 1
print counter
clkLastState = clkState
sleep(0.01)
finally:
GPIO.cleanup()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment