-
Notifications
You must be signed in to change notification settings - Fork 0
/
WS2801Controller.py
36 lines (30 loc) · 1.13 KB
/
WS2801Controller.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
# Simple demo of of the WS2801/SPI-like addressable RGB LED lights.
import time
import RPi.GPIO as GPIO
# Import the WS2801 module.
import Adafruit_WS2801
import Adafruit_GPIO.SPI as SPI
class WS2801Controller:
PIXEL_COUNT = 160
SPI_PORT = 0
SPI_DEVICE = 0
powerFlag = False
pixels = Adafruit_WS2801.WS2801Pixels(PIXEL_COUNT, spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE),
gpio=GPIO)
@staticmethod
def change_color(self, color):
for i in range(self.pixels.count()):
self.pixels.set_pixel(i, Adafruit_WS2801.RGB_to_color(color[0], color[1], color[2]))
self.pixels.show()
@staticmethod
def toggle_power():
WS2801Controller.powerFlag = not WS2801Controller.powerFlag
@staticmethod
def power():
if not WS2801Controller.powerFlag:
WS2801Controller.change_color(WS2801Controller, color=(204, 0, 204))
WS2801Controller.toggle_power()
else:
WS2801Controller.pixels.clear()
WS2801Controller.pixels.show()
WS2801Controller.toggle_power()