-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLedEffects.py
More file actions
51 lines (33 loc) · 1012 Bytes
/
LedEffects.py
File metadata and controls
51 lines (33 loc) · 1012 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
41
42
43
44
45
46
47
48
49
import time
import colour as c
import threading, queue
__author__ = 'kurt'
class LedEffects():
def __init__(self,header,ser,NUM_LEDS):
self.header = header
self.ser = ser
self.NUM_LEDS = NUM_LEDS
###################
#
# Utilities
#
###################
def leds_list_to_byte(self,leds_list):
temp_string = self.header
for each in leds_list:
for colour in each.get_rgb():
temp_string += bytes([int(255 * colour)])
return temp_string
###################
#
# Effects
#
###################
def chase(self,run_time, colour = c.Color(rgb=(1, 1, 1)), offcolour =c.Color("black")):
t_end = time.time() + run_time
while time.time() < t_end:
for i in range(self.NUM_LEDS):
leds_list = [ offcolour ] * self.NUM_LEDS
leds_list[i] = colour
self.ser.write(self.leds_list_to_byte(leds_list))
time.sleep(0.01)