-
Notifications
You must be signed in to change notification settings - Fork 1
/
python_client.py
90 lines (75 loc) · 2.15 KB
/
python_client.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import serial
import time
LED_COUNT = 60
SHORT_DELAY_TIME = 0.008
LONG_DELAY_TIME = 0.09
SERIAL_PORT = '/dev/ttyUSB0'
BAUDRATE = 9600
byteArray = bytearray(4)
SERIAL = serial.Serial(SERIAL_PORT, BAUDRATE, timeout=1)
def setSingleLedToColor(led,R,G,B):
byteArray = bytearray(4)
byteArray[0] = led
byteArray[1] = R
byteArray[2] = G
byteArray[3] = B
SERIAL.write(byteArray)
# delay to give arduino some time to proces request
time.sleep(SHORT_DELAY_TIME)
def applyChanges():
byteArray = bytearray(4)
byteArray[0] = 255
byteArray[1] = 0
byteArray[2] = 0
byteArray[3] = 0
SERIAL.write(byteArray)
# delay to give arduino some time to proces request
time.sleep(SHORT_DELAY_TIME)
def setAllLedsToColor(R,G,B):
byteArray[0] = 254
byteArray[1] = int(R/10)
byteArray[2] = int(G/10)
byteArray[3] = int(B/10)
SERIAL.write(byteArray)
# delay to give arduino some time to proces request
time.sleep(LONG_DELAY_TIME)
def endlessRainbow():
while True:
setAllLedsToColor(248, 12, 18)
applyChanges()
setAllLedsToColor(238, 17, 0)
applyChanges()
setAllLedsToColor(255, 51, 17)
applyChanges()
setAllLedsToColor(255, 68, 34)
applyChanges()
setAllLedsToColor(255, 102, 68)
applyChanges()
setAllLedsToColor(255, 153, 51)
applyChanges()
setAllLedsToColor(254, 174, 45)
applyChanges()
setAllLedsToColor(204, 187, 51)
applyChanges()
setAllLedsToColor(208, 195, 16)
applyChanges()
setAllLedsToColor(170, 204, 34)
applyChanges()
setAllLedsToColor(105, 208, 37)
applyChanges()
setAllLedsToColor(34, 204, 170)
applyChanges()
setAllLedsToColor(18, 189, 185)
applyChanges()
setAllLedsToColor(17, 170, 187)
applyChanges()
setAllLedsToColor(68, 68, 221)
applyChanges()
setAllLedsToColor(51, 17, 187)
applyChanges()
setAllLedsToColor(59, 12, 189)
applyChanges()
setAllLedsToColor(68, 34, 153)
applyChanges()
endlessRainbow()
SERIAL.close()