led_control/server/example/rainbow.py
2020-06-06 21:50:43 +02:00

47 lines
924 B
Python

import time
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 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()
def main():
DELAY = 0.1
r = 255
g = 0
b = 0
while True:
while r > 0:
r = r-1
g = g+1
set_color(r,g,b)
time.sleep(DELAY)
while g > 0:
g = g-1
b = b+1
set_color(r,g,b)
time.sleep(DELAY)
while b > 0:
b = b-1
r = r+1
set_color(r,g,b)
time.sleep(DELAY)
if __name__ == "__main__":
main()