X-Git-Url: http://handorf.org/code/?p=rb-clock.git;a=blobdiff_plain;f=python%2Frotor-test.py;fp=python%2Frotor-test.py;h=5dcebd7824b24a338192cea9b3290822390e4a4f;hp=0000000000000000000000000000000000000000;hb=d29015560feafdb91746173de224a5fe692f7b6b;hpb=f2580fcc9470d1ac688ca9b6edd87666784eaf6b diff --git a/python/rotor-test.py b/python/rotor-test.py new file mode 100644 index 0000000..5dcebd7 --- /dev/null +++ b/python/rotor-test.py @@ -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) +