-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathchange-color.py
51 lines (43 loc) · 1.75 KB
/
change-color.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
from rpi_ws281x import PixelStrip, Color
from api import engine
import sqlalchemy
from settings import Settings
import sys
import time
Session = sqlalchemy.orm.sessionmaker()
Session.configure(bind=engine)
session = Session()
LED_COUNT = 300 # Number of LED pixels.
LED_PIN = 18 # GPIO pin connected to the pixels (18 uses PWM!).
# LED_PIN = 10 # GPIO pin connected to the pixels (10 uses SPI /dev/spidev0.0).
LED_FREQ_HZ = 800000 # LED signal frequency in hertz (usually 800khz)
LED_DMA = 10 # DMA channel to use for generating signal (try 10)
LED_BRIGHTNESS = 255 # Set to 0 for darkest and 255 for brightest
# True to invert the signal (when using NPN transistor level shift)
LED_INVERT = False
LED_CHANNEL = 0 # set to '1' for GPIOs 13, 19, 41, 45 or 53
# Create NeoPixel object with appropriate configuration.
strip = PixelStrip(LED_COUNT, LED_PIN, LED_FREQ_HZ, LED_DMA,
LED_INVERT, LED_BRIGHTNESS, LED_CHANNEL)
# Intialize the library (must be called once before other functions).
strip.begin()
settingsJiri = session.query(Settings).filter(
Settings.type == "COLOR_JIRI").one()
settingsBelca = session.query(Settings).filter(
Settings.type == "COLOR_BELCA").one()
session.close()
engine.dispose()
colorJiri = settingsJiri.value.lstrip("#")
colorRGBJiri = tuple(int(colorJiri[i:i+2], 16) for i in (0, 2, 4))
colorBelca = settingsBelca.value.lstrip("#")
colorRGBBelca = tuple(
int(colorBelca[i:i+2], 16) for i in (0, 2, 4))
for i in range(0, 135):
strip.setPixelColor(
i, Color(colorRGBJiri[0], colorRGBJiri[1], colorRGBJiri[2]))
strip.show()
for i in range(135, 300):
strip.setPixelColor(
i, Color(colorRGBBelca[0], colorRGBBelca[1], colorRGBBelca[2]))
strip.show()
print("ok")