forked from IzzyBrand/ledvis
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstrips.py
95 lines (72 loc) · 4.08 KB
/
strips.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
from neopixel import *
from config import *
from rpi_ws281x import Adafruit_NeoPixel, Color
import numpy as np
import time
class Strips:
def __init__(self):
self.strip1 = Adafruit_NeoPixel(LED_1_COUNT, LED_1_PIN, LED_1_FREQ_HZ, LED_1_DMA, LED_1_INVERT, LED_1_BRIGHTNESS, LED_1_CHANNEL)
self.strip2 = Adafruit_NeoPixel(LED_2_COUNT, LED_2_PIN, LED_2_FREQ_HZ, LED_2_DMA, LED_2_INVERT, LED_2_BRIGHTNESS, LED_2_CHANNEL) # IZZY: strip2 disabled
# self.strip1 = neopixel(LED_1_COUNT, LED_1_PIN, LED_1_FREQ_HZ, LED_1_DMA, LED_1_INVERT, LED_1_BRIGHTNESS, LED_1_CHANNEL)
# self.strip2 = neopixel(LED_2_COUNT, LED_2_PIN, LED_2_FREQ_HZ, LED_2_DMA, LED_2_INVERT, LED_2_BRIGHTNESS, LED_2_CHANNEL) # IZZY: strip2 disabled
self.strip1.begin()
self.strip2.begin() # IZZY: strip2 disabled
self.prev_write_time = time.time()
def set_brightness(self, brightness):
self.strip1.setBrightness(brightness)
self.strip2.setBrightness(brightness) # IZZY: strip2 disabled
def write(self, colors):
# set the LED self.strips to those colors
for i, c in enumerate(colors.astype(int)):
color = Color(*c)
self.strip1.setPixelColor(i, color)
self.strip2.setPixelColor(i, color) # IZZY: strip2 disabled
# we require a sleep after each each write for the strips to finish updating
# make sure we've slept enough since the last write
sleep_time = LED_WRITE_DELAY - (time.time() - self.prev_write_time)
if sleep_time > 0: time.sleep(sleep_time)
# write to the LED strips (with GPIO)
self.strip1.show()
time.sleep(LED_WRITE_DELAY) # IZZY: strip2 disabled
self.strip2.show() # IZZY: strip2 disabled
self.prev_write_time = time.time() # save for the next loop
class StripR:
def __init__(self):
self.strip1 = Adafruit_NeoPixel(LED_1_COUNT, LED_1_PIN, LED_1_FREQ_HZ, LED_1_DMA, LED_1_INVERT, LED_1_BRIGHTNESS, LED_1_CHANNEL)
# self.strip1 = neopixel(LED_1_COUNT, LED_1_PIN, LED_1_FREQ_HZ, LED_1_DMA, LED_1_INVERT, LED_1_BRIGHTNESS, LED_1_CHANNEL)
self.strip1.begin()
self.prev_write_time = time.time()
def set_brightness(self, brightness):
self.strip1.setBrightness(brightness)
def write(self, colors):
# set the LED self.strips to those colors
for i, c in enumerate(colors.astype(int)):
color = Color(*c)
self.strip1.setPixelColor(i, color)
# we require a sleep after each each write for the strips to finish updating
# make sure we've slept enough since the last write
sleep_time = LED_WRITE_DELAY - (time.time() - self.prev_write_time)
if sleep_time > 0: time.sleep(sleep_time)
# write to the LED strips (with GPIO)
self.strip1.show()
self.prev_write_time = time.time() # save for the next loop
class StripL:
def __init__(self):
self.strip2 = Adafruit_NeoPixel(LED_2_COUNT, LED_2_PIN, LED_2_FREQ_HZ, LED_2_DMA, LED_2_INVERT, LED_2_BRIGHTNESS, LED_2_CHANNEL) # IZZY: strip2 disabled
# self.strip2 = neopixel(LED_2_COUNT, LED_2_PIN, LED_2_FREQ_HZ, LED_2_DMA, LED_2_INVERT, LED_2_BRIGHTNESS, LED_2_CHANNEL) # IZZY: strip2 disabled
self.strip2.begin() # IZZY: strip2 disabled
self.prev_write_time = time.time()
def set_brightness(self, brightness):
self.strip2.setBrightness(brightness) # IZZY: strip2 disabled
def write(self, colors):
# set the LED self.strips to those colors
for i, c in enumerate(colors.astype(int)):
color = Color(*c)
self.strip2.setPixelColor(i, color) # IZZY: strip2 disabled
# we require a sleep after each each write for the strips to finish updating
# make sure we've slept enough since the last write
sleep_time = LED_WRITE_DELAY - (time.time() - self.prev_write_time)
if sleep_time > 0: time.sleep(sleep_time)
#time.sleep(LED_WRITE_DELAY - 0.00155) # IZZY: strip2 disabled
self.strip2.show() # IZZY: strip2 disabled
self.prev_write_time = time.time() # save for the next loop