more backups
[rb-clock.git] / python / rotor-test.py
1 import time
2 import gaugette.rotary_encoder
3 import gaugette.gpio
4 import gaugette.switch
5
6 A_PIN  = 5
7 B_PIN  = 4
8 SW_PIN = 2
9
10 gpio = gaugette.gpio.GPIO()
11 encoder = gaugette.rotary_encoder.RotaryEncoder(gpio, A_PIN, B_PIN)
12 encoder.start()
13 switch = gaugette.switch.Switch(gpio, SW_PIN)
14 last_state = None
15 sw = gaugette.switch.Switch(gpio, SW_PIN)
16 last_state = sw.get_state()
17
18 while True:
19   delta = encoder.get_cycles()
20   state = sw.get_state()
21   if state != last_state:
22     print "switch %d" % state
23     last_state = state
24
25   if delta!=0:
26     print "rotate %d" % delta
27   else:
28     time.sleep(0.1)
29