more backups
[rb-clock.git] / python / rotor-test2.py
diff --git a/python/rotor-test2.py b/python/rotor-test2.py
new file mode 100644 (file)
index 0000000..2fdc836
--- /dev/null
@@ -0,0 +1,35 @@
+from RPi import GPIO
+from time import sleep
+
+clk = 23
+dt = 24
+sw = 27
+
+GPIO.setmode(GPIO.BCM)
+GPIO.setup(clk, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
+GPIO.setup(dt, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
+GPIO.setup(sw, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
+
+counter = 0
+clkLastState = GPIO.input(clk)
+swLastState = GPIO.input(sw)
+
+try:
+
+        while True:
+                clkState = GPIO.input(clk)
+                dtState = GPIO.input(dt)
+               swState = GPIO.input(sw)
+                if clkState != clkLastState:
+                        if dtState != clkState:
+                                counter += 1
+                        else:
+                                counter -= 1
+                        print counter
+                clkLastState = clkState
+               if swState != swLastState:
+                        print "Pushed"
+               swLastState = swState
+                sleep(0.01)
+finally:
+        GPIO.cleanup()