- Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample.py
More file actions
Latest commit
40 lines (31 loc) · 951 Bytes
/
Copy pathexample.py
File metadata and controls
40 lines (31 loc) · 951 Bytes
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
importtime
importthreading
fromespalexaimportEspalexa
# create a espalexa object
espalexa=Espalexa()
# callback function for dimmable device
defcallback(brightness):
print("Brightness: "+str(brightness))
# callback function for color device
defcallback_color(brightness, rgb):
print("Brightness: "+str(brightness))
print(rgb)
print("Red: "+str((rgb>>16) &0xFF) +", Green: "+str((rgb>>8) &0xFF) +", Blue: "+str(rgb&0xFF))
defloop(espalexa):
whileTrue:
espalexa.loop()
time.sleep(1)
if__name__=="__main__":
# add devices
espalexa.addDevice("Light without color", callback, "dimmable")
espalexa.addDevice("Light with color", callback_color, "extendedcolor")
# initialize espalexa
espalexa.begin()
# start the espalexa loop thread
t=threading.Thread(target=loop, args= (espalexa,))
t.daemon=True
t.start()
# keep the script running
whileTrue:
print(".")
time.sleep(60)