import time
import _rpi_ws281x as ws
LED_CHANNEL = 0
LED_COUNT = 16 LED_FREQ_HZ = 800000 LED_DMA_NUM = 10 LED_GPIO = 18 LED_BRIGHTNESS = 255 LED_INVERT = 0 LED_STRIP = ws.SK6812W_STRIP
DOT_COLORS = [ 0x200000, 0x201000, 0x202000, 0x002000, 0x002020, 0x000020, 0x100010, 0x200010 ]
leds = ws.new_ws2811_t()
for channum in range(2):
channel = ws.ws2811_channel_get(leds, channum)
ws.ws2811_channel_t_count_set(channel, 0)
ws.ws2811_channel_t_gpionum_set(channel, 0)
ws.ws2811_channel_t_invert_set(channel, 0)
ws.ws2811_channel_t_brightness_set(channel, 0)
channel = ws.ws2811_channel_get(leds, LED_CHANNEL)
ws.ws2811_channel_t_count_set(channel, LED_COUNT)
ws.ws2811_channel_t_gpionum_set(channel, LED_GPIO)
ws.ws2811_channel_t_invert_set(channel, LED_INVERT)
ws.ws2811_channel_t_brightness_set(channel, LED_BRIGHTNESS)
ws.ws2811_channel_t_strip_type_set(channel, LED_STRIP)
ws.ws2811_t_freq_set(leds, LED_FREQ_HZ)
ws.ws2811_t_dmanum_set(leds, LED_DMA_NUM)
resp = ws.ws2811_init(leds)
if resp != ws.WS2811_SUCCESS:
message = ws.ws2811_get_return_t_str(resp)
raise RuntimeError('ws2811_init failed with code {0} ({1})'.format(resp, message))
try:
offset = 0
while True:
for i in range(LED_COUNT):
color = DOT_COLORS[(i + offset) % len(DOT_COLORS)]
ws.ws2811_led_set(channel, i, color)
resp = ws.ws2811_render(leds)
if resp != ws.WS2811_SUCCESS:
message = ws.ws2811_get_return_t_str(resp)
raise RuntimeError('ws2811_render failed with code {0} ({1})'.format(resp, message))
time.sleep(0.25)
offset += 1
finally:
ws.ws2811_fini(leds)
ws.delete_ws2811_t(leds)