-
Notifications
You must be signed in to change notification settings - Fork 0
/
rotaryLights_pro.py
55 lines (41 loc) · 1.17 KB
/
rotaryLights_pro.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# Test script for selecting and toggling lights via rotary encoder
# Mike Meaney 2015
#Import stuff for the rotary encoder
import gaugette.rotary_encoder
import gaugette.switch
#Declare the pins for the rotary encoder
A_PIN = 27
B_PIN = 28
SW_PIN = 29
#Initiate the rotary encoder's worker
encoder = gaugette.rotary_encoder.RotaryEncoder.Worker(A_PIN, B_PIN)
encoder.start()
switch = gaugette.switch.Switch(SW_PIN)
last_state = None
clicks = 0
realClicks = 0
# Import stuff for Hue Lifx
from phue import Bridge ##The Hue Api
import lifx ##The LIFX Api
# Make Connections to and pool Hue / lifx
# Create LIFX Connection
xLights = lifx.Lifx()
#Create Hue Connection
b = Bridge('192.168.0.45')
hLights = b.get_light_objects()
hGroups = b.get_group()
#Do this stuff, for like, forever...
while True:
delta = encoder.get_delta()
if delta!=0:
# print ("rotate %d " % delta)
clicks += delta
# print (clicks)
# print (clicks % 4)
if clicks % 4 == 0:
# print ("DERP, THAT'S ONE CLICK REALLY!!")
print (clicks / 4)
sw_state = switch.get_state()
if sw_state != last_state:
print ("switch %d" % sw_state)
last_state = sw_state