more backups
[rb-clock.git] / python / rotor-test.py
diff --git a/python/rotor-test.py b/python/rotor-test.py
new file mode 100644 (file)
index 0000000..5dcebd7
--- /dev/null
@@ -0,0 +1,29 @@
+import time
+import gaugette.rotary_encoder
+import gaugette.gpio
+import gaugette.switch
+
+A_PIN  = 5
+B_PIN  = 4
+SW_PIN = 2
+
+gpio = gaugette.gpio.GPIO()
+encoder = gaugette.rotary_encoder.RotaryEncoder(gpio, A_PIN, B_PIN)
+encoder.start()
+switch = gaugette.switch.Switch(gpio, SW_PIN)
+last_state = None
+sw = gaugette.switch.Switch(gpio, SW_PIN)
+last_state = sw.get_state()
+
+while True:
+  delta = encoder.get_cycles()
+  state = sw.get_state()
+  if state != last_state:
+    print "switch %d" % state
+    last_state = state
+
+  if delta!=0:
+    print "rotate %d" % delta
+  else:
+    time.sleep(0.1)
+