from machine import Pin
import time
import neopixel
ws_pin = 13
NUMPIXELS = 64 # NeoPixel ring size
pixDELAY = 100 # Delay for pixel persistence
def hsv_to_rgb(h, s, v):
i = int(h * 6.)
f = (h * 6.) - i
p = v * (1. - s)
q = v * (1. - s * f)
t = v * (1. - s * (1. - f))
i = i % 6
if i == 0:
return int(v * 255), int(t * 255), int(p * 255)
elif i == 1:
return int(q * 255), int(v * 255), int(p * 255)
elif i == 2:
return int(p * 255), int(v * 255), int(t * 255)
elif i == 3:
return int(p * 255), int(q * 255), int(v * 255)
elif i == 4:
return int(t * 255), int(p * 255), int(v * 255)
elif i == 5:
return int(v * 255), int(p * 255), int(q * 255)
# https://toptechboy.com/convert-hsv-to-rgb-in-micropython/
def getRGB(deg):
m=1/60
if deg>=0 and deg<60:
R=1
G=0
B=m*deg
if deg>=60 and deg<120:
R=1-m*(deg-60)
G=0
B=1
if deg>=120 and deg<180:
R=0
G=m*(deg-120)
B=1
if deg>=180 and deg<240:
R=0
G=1
B=1-m*(deg-180)
if deg>=240 and deg<300:
R=m*(deg-240)
G=1
B=0
if deg>=300 and deg<360:
R=1
G=1-m*(deg-300)
B=0
myColor=(R,G,B)
return myColor
# Start Function
if __name__ == '__main__':
# Create a NeoPixel object
pixels = neopixel.NeoPixel(Pin(ws_pin), NUMPIXELS)
for n in range(0,60, 1):
pixels[n] = getRGB(n*6) # Set the current pixel to the rainbow color
print(pixels[n])
pixels.write() # Update pixel colors
time.sleep_ms(pixDELAY)