-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlightTest.py
301 lines (269 loc) · 7.74 KB
/
lightTest.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
#!/usr/bin/env python
#
# Python Script for controlling VBS lighting modules from a Raspberry Pi
#
# Written By Les Holdeman 02/2018 using Python documentation:
# smbus - https://pypi.python.org/pypi/smbus2/0.2.0
# socket - https://docs.python.org/2/library/socket.html
# time - https://docs.python.org/2/library/time.html modules
#
# Commands for various colors of each LED
# LED 1 Red - <addr> 0x14 0x01
# LED 1 Green - <addr> 0x14 0x02
# LED 1 Yellow - <addr> 0x14 0x03
# LED 1 Blue - <addr> 0x14 0x04
# LED 1 Purple - <addr> 0x14 0x05
# LED 1 Light Blue - <addr> 0x14 0x06
# LED 1 White - <addr> 0x14 0x07
#
# LED 2 Red - <addr> 0x14 0x08
# LED 2 Green - <addr> 0x14 0x10
# LED 2 Yellow - <addr> 0x14 0x18
# LED 2 Blue - <addr> 0x14 0x20
# LED 2 Purple - <addr> 0x14 0x28
# LED 2 Light Blue - <addr> 0x14 0x30
# LED 2 White - <addr> 0x14 0x38
#
# LED 3 Red - <addr> 0x14 0x40
# LED 3 Green - <addr> 0x14 0x80
# LED 3 Yellow - <addr> 0x14 0xC0
# LED 3 Blue - <addr> 0x15 0x01
# LED 3 Purple - <addr> 0x14 0x40 and <addr> 0x15 0x01
# LED 3 Light Blue - <addr> 0x14 0x80 and <addr> 0x15 0x01
# LED 3 White - <addr> 0x14 0xC0 and <addr> 0x15 0x01
#
# LED 4 Red - <addr> 0x15 0x02
# LED 4 Green - <addr> 0x15 0x04
# LED 4 Yellow - <addr> 0x15 0x06
# LED 4 Blue - <addr> 0x15 0x08
# LED 4 Purple - <addr> 0x15 0x0A
# LED 4 Light Blue - <addr> 0x15 0x0C
# LED 4 White - <addr> 0x15 0x0E
#
# LED 5 Red - <addr> 0x15 0x10
# LED 5 Green - <addr> 0x15 0x20
# LED 5 Yellow - <addr> 0x15 0x30
# LED 5 Blue - <addr> 0x15 0x40
# LED 5 Purple - <addr> 0x15 0x50
# LED 5 Light Blue - <addr> 0x15 0x60
# LED 5 White - <addr> 0x15 0x70
#
# Standby LEDs - <addr> 0x15 0x80
import smbus
import time
import socket
#variables
bus = smbus.SMBus(1) # Use 1 for Rev 2 Pi, Use 0 for Rev 1 Pi
swirlTime = 0.1
blinkTime = 0.2
# Device Addresses
device0 = 0x20
device1 = 0x21
# Registers A are for GPA pins, Registers B are for GPB pins
IODIRA = 0x00 # Register A for pin direction
IODIRB = 0x01 # Register B for pin direction
OLATA = 0x14 # Register A for outputs
OLATB = 0x15 # Register B for outputs
# Setup
# Set GPA and GPB pins to outputs on all devices
bus.write_byte_data(device0,IODIRA,0x00)
bus.write_byte_data(device0,IODIRB,0x00)
#bus.write_byte_data(device1,IODIRA,0x00)
#bus.write_byte_data(device1,IODIRB,0x00)
# Set all outputs to off on all devices
bus.write_byte_data(device0,OLATA,0x00)
bus.write_byte_data(device0,OLATB,0x00)
#bus.write_byte_data(device1,OLATA,0x00)
#bus.write_byte_data(device1,OLATB,0x00)
# Functions
def idleState(addr):
bus.write_byte_data(addr,OLATB,0x80)
return;
def redSwirl(addr):
bus.write_byte_data(addr,OLATA,0x01)
time.sleep(swirlTime)
bus.write_byte_data(addr,OLATA,0x08)
time.sleep(swirlTime)
bus.write_byte_data(addr,OLATA,0x40)
time.sleep(swirlTime)
bus.write_byte_data(addr,OLATA,0x00)
bus.write_byte_data(addr,OLATB,0x02)
time.sleep(swirlTime)
bus.write_byte_data(addr,OLATB,0x10)
time.sleep(swirlTime)
bus.write_byte_data(addr,OLATB,0x00)
time.sleep(swirlTime)
return;
def blueSwirl(addr):
bus.write_byte_data(addr,OLATA,0x02)
time.sleep(swirlTime)
bus.write_byte_data(addr,OLATA,0x10)
time.sleep(swirlTime)
bus.write_byte_data(addr,OLATA,0x80)
time.sleep(swirlTime)
bus.write_byte_data(addr,OLATA,0x00)
bus.write_byte_data(addr,OLATB,0x04)
time.sleep(swirlTime)
bus.write_byte_data(addr,OLATB,0x20)
time.sleep(swirlTime)
bus.write_byte_data(addr,OLATB,0x00)
time.sleep(swirlTime)
return;
def greenSwirl(addr):
bus.write_byte_data(addr,OLATA,0x04)
time.sleep(swirlTime)
bus.write_byte_data(addr,OLATA,0x20)
time.sleep(swirlTime)
bus.write_byte_data(addr,OLATA,0x00)
bus.write_byte_data(addr,OLATB,0x01)
time.sleep(swirlTime)
bus.write_byte_data(addr,OLATB,0x08)
time.sleep(swirlTime)
bus.write_byte_data(addr,OLATB,0x40)
time.sleep(swirlTime)
bus.write_byte_data(addr,OLATB,0x00)
time.sleep(swirlTime)
return;
def purpleSwirl(addr):
bus.write_byte_data(addr,OLATA,0x03)
time.sleep(swirlTime)
bus.write_byte_data(addr,OLATA,0x18)
time.sleep(swirlTime)
bus.write_byte_data(addr,OLATA,0xc0)
time.sleep(swirlTime)
bus.write_byte_data(addr,OLATA,0x00)
bus.write_byte_data(addr,OLATB,0x06)
time.sleep(swirlTime)
bus.write_byte_data(addr,OLATB,0x30)
time.sleep(swirlTime)
bus.write_byte_data(addr,OLATB,0x00)
time.sleep(swirlTime)
return;
def yellowSwirl(addr):
bus.write_byte_data(addr,OLATA,0x05)
time.sleep(swirlTime)
bus.write_byte_data(addr,OLATA,0x28)
time.sleep(swirlTime)
bus.write_byte_data(addr,OLATA,0x40)
bus.write_byte_data(addr,OLATB,0x01)
time.sleep(swirlTime)
bus.write_byte_data(addr,OLATA,0x00)
bus.write_byte_data(addr,OLATB,0x0A)
time.sleep(swirlTime)
bus.write_byte_data(addr,OLATB,0x50)
time.sleep(swirlTime)
bus.write_byte_data(addr,OLATB,0x00)
time.sleep(swirlTime)
return;
def lightBlueSwirl(addr):
bus.write_byte_data(addr,OLATA,0x06)
time.sleep(swirlTime)
bus.write_byte_data(addr,OLATA,0x30)
time.sleep(swirlTime)
bus.write_byte_data(addr,OLATA,0x80)
bus.write_byte_data(addr,OLATB,0x01)
time.sleep(swirlTime)
bus.write_byte_data(addr,OLATA,0x00)
bus.write_byte_data(addr,OLATB,0x0C)
time.sleep(swirlTime)
bus.write_byte_data(addr,OLATB,0x60)
time.sleep(swirlTime)
bus.write_byte_data(addr,OLATB,0x00)
time.sleep(swirlTime)
return;
def whiteSwirl(addr):
bus.write_byte_data(addr,OLATA,0x07)
time.sleep(swirlTime)
bus.write_byte_data(addr,OLATA,0x38)
time.sleep(swirlTime)
bus.write_byte_data(addr,OLATA,0xC0)
bus.write_byte_data(addr,OLATB,0x01)
time.sleep(swirlTime)
bus.write_byte_data(addr,OLATA,0x00)
bus.write_byte_data(addr,OLATB,0x0E)
time.sleep(swirlTime)
bus.write_byte_data(addr,OLATB,0x70)
time.sleep(swirlTime)
bus.write_byte_data(addr,OLATB,0x00)
time.sleep(swirlTime)
return;
def redBlink(addr):
bus.write_byte_data(addr,OLATA,0x49)
bus.write_byte_data(addr,OLATB,0x12)
time.sleep(blinkTime)
bus.write_byte_data(addr,OLATA,0x00)
bus.write_byte_data(addr,OLATB,0x00)
time.sleep(blinkTime)
return;
def blueBlink(addr):
bus.write_byte_data(addr,OLATA,0x92)
bus.write_byte_data(addr,OLATB,0x24)
time.sleep(blinkTime)
bus.write_byte_data(addr,OLATA,0x00)
bus.write_byte_data(addr,OLATB,0x00)
time.sleep(blinkTime)
return;
def purpleBlink(addr):
bus.write_byte_data(addr,OLATA,0xDB)
bus.write_byte_data(addr,OLATB,0x36)
time.sleep(blinkTime)
bus.write_byte_data(addr,OLATA,0x00)
bus.write_byte_data(addr,OLATB,0x00)
time.sleep(blinkTime)
return;
def greenBlink(addr):
bus.write_byte_data(addr,OLATA,0x24)
bus.write_byte_data(addr,OLATB,0x49)
time.sleep(blinkTime)
bus.write_byte_data(addr,OLATA,0x00)
bus.write_byte_data(addr,OLATB,0x00)
time.sleep(blinkTime)
return;
def yellowBlink(addr):
bus.write_byte_data(addr,OLATA,0x6D)
bus.write_byte_data(addr,OLATB,0x5B)
time.sleep(blinkTime)
bus.write_byte_data(addr,OLATA,0x00)
bus.write_byte_data(addr,OLATB,0x00)
time.sleep(blinkTime)
return;
def lightBlueBlink(addr):
bus.write_byte_data(addr,OLATA,0xB6)
bus.write_byte_data(addr,OLATB,0x6D)
time.sleep(blinkTime)
bus.write_byte_data(addr,OLATA,0x00)
bus.write_byte_data(addr,OLATB,0x00)
time.sleep(blinkTime)
return;
def whiteBlink(addr):
bus.write_byte_data(addr,OLATA,0xFF)
bus.write_byte_data(addr,OLATB,0x7F)
time.sleep(blinkTime)
bus.write_byte_data(addr,OLATA,0x00)
bus.write_byte_data(addr,OLATB,0x00)
time.sleep(blinkTime)
return;
def goodState():
return;
def badState():
return;
def errorState():
purpleBlink(device0)
purpleBlink(device1)
return;
# Start the loop
while True :
lightBlueBlink(device0)
lightBlueSwirl(device0)
blueBlink(device0)
blueSwirl(device0)
purpleBlink(device0)
purpleSwirl(device0)
redBlink(device0)
redSwirl(device0)
yellowBlink(device0)
yellowSwirl(device0)
greenBlink(device0)
greenSwirl(device0)
whiteBlink(device0)
whiteSwirl(device0)