from machine import Pin
import neopixel
import time
NUM_PIXELS=16
DATA_PIN=15
np= neopixel.NeoPixel(Pin(DATA_PIN), NUM_PIXELS)
def clear():
for i in range(NUM_PIXELS):
np[i] = (0, 0, 0)
np.write()
def wheel(pos):
if pos < 85:
return (255 - pos * 3, pos * 3, 0)
elif pos < 170:
pos -= 85
return (0, pos * 3, 255 - pos * 3)
else:
pos -= 170
return (pos * 3, 255 - pos * 3, 0)
def color_wipe(color, delay=0.05):
for i in range(NUM_PIXELS):
np[i] = color
np.write()
time.sleep(delay)
def chase(color, delay=0.05):
clear()
for i in range(NUM_PIXELS):
np[i] = color
np.write()
time.sleep(delay)
np[i] = (0, 0, 0)
def rainbow(delay=0.02):
for j in range(256):
for i in range(NUM_PIXELS):
idx = (i * 256 // NUM_PIXELS) + j
np[i] = wheel(idx & 255)
np.write()
time.sleep(delay)
while True:
color_wipe((255, 0, 0))
color_wipe((0, 255, 0))
color_wipe((0, 0, 255))
chase((255, 255, 0))
rainbow()