Rainbow on NeoPixels
Cycle a rainbow along a strip of WS2812 / NeoPixel LEDs.
A starter program from the MantisIDE Full IDE (Tools › Examples). Press Open in Full IDE to run it on your board, change it, and save it as your own.
# Cycle a rainbow along a strip of WS2812 / NeoPixel LEDs.
from machine import Pin
import neopixel, time
COUNT = 8
strip = neopixel.NeoPixel(Pin(5), COUNT)
def wheel(pos):
pos %= 255
if pos < 85:
return (255 - pos * 3, pos * 3, 0)
if pos < 170:
pos -= 85
return (0, 255 - pos * 3, pos * 3)
pos -= 170
return (pos * 3, 0, 255 - pos * 3)
step = 0
while True:
for i in range(COUNT):
strip[i] = wheel(step + i * 255 // COUNT)
strip.write()
step += 3
time.sleep_ms(30)
Comments