26 lines
562 B
Python
26 lines
562 B
Python
import RPi.GPIO as GPIO
|
|
import Adafruit_WS2801
|
|
import Adafruit_GPIO.SPI as SPI
|
|
|
|
PIXEL_COUNT = 32
|
|
|
|
SPI_PORT = 0
|
|
SPI_DEVICE = 0
|
|
pixels = Adafruit_WS2801.WS2801Pixels(PIXEL_COUNT, spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE), gpio=GPIO)
|
|
|
|
def hex_to_rgb(hex):
|
|
r = int(hex[0:2],16)
|
|
g = int(hex[2:4],16)
|
|
b = int(hex[4:6],16)
|
|
print(r,g,b)
|
|
return r,g,b
|
|
|
|
def set_color(r,g,b):
|
|
for i in range(pixels.count()):
|
|
pixels.set_pixel(i, Adafruit_WS2801.RGB_to_color(r,g,b))
|
|
pixels.show()
|
|
|
|
def clear_pixels():
|
|
pixels.clear()
|
|
pixels.show()
|