WS2812Strip
The snippet can be accessed without any authentication.
Authored by
Jannis Konrad
main.py 981 B
#Init IO
from machine import Pin, PWM
from neopixel import NeoPixel
pin = Pin(2, Pin.OUT) # set GPIO0(D4) to output to drive NeoPixels
np = NeoPixel(pin, 30) # create NeoPixel driver on GPIO0 for 30 pixels
import urandom
val = 0
hue = 0
dir = +0.001
scale = 10
hold = 0
def update(x=None):
global val, hue, dir, scale, hold
#start = time.ticks_ms()
if abs(hue-val) < 0.001:
if hold:
hold -= 1
else:
val = urandom.getrandbits(8)/2.**8
dir *= -1
#print(val*dir)
hold += 1000
else:
hue += dir #-= abs(hue-val)*0.01
hue %= 1.0
r, g, b = hsv_to_rgb(hue, 0.5, 1.0)
np.buf[3:] = np.buf[:-3]
np[0] = (int(r*scale),int(g*scale),int(b*scale))
np.write()
#print("Loop took:", time.ticks_diff(time.ticks_ms(), start), "ms")
#Start update timer
from machine import Timer
tim = Timer(-1)
#tim.deinit()
tim.init(period=10, mode=Timer.PERIODIC, callback=update)
Please register or sign in to comment