winter-special-projects / micropython

MicroPython - a lean and efficient Python implementation for microcontrollers and constrained systems
https://micropython.org
Other
0 stars 0 forks source link

neopixel support #2

Open graeme-winter opened 1 year ago

graeme-winter commented 1 year ago
>>> import neopixel
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: module not found

also make this not the case (which is a bit more weird)

graeme-winter commented 1 year ago
import time
import neopixel
import machine

pixels = neopixel.NeoPixel(machine.Pin(88, machine.Pin.OUT), 1)

def hsv2rgb(h, s, v):
    h = h % 360
    c = v * s
    x = c * (1 - abs(((h/60.) % 2) - 1))
    m = v - c
    if 0 <= h < 60:
        _r, _g, _b = c, x, 0
    elif 60 <= h < 120:
        _r, _g, _b = x, c, 0
    elif 120 <= h < 180:
        _r, _g, _b = 0, c, x
    elif 180 <= h < 240:
        _r, _g, _b = 0, x, c
    elif 240 <= h < 300:
        _r, _g, _b = x, 0, c
    elif 300 <= h < 360:
        _r, _g, _b = c, 0, x
    return int((_r + m) * 0xff), int((_g + m) * 0xff), int((_b + m) * 0xff)

while True:
    for j in range(360):
        r, g, b = hsv2rgb(j, 1, 0.125)
        pixels.fill((r, g, b))
        pixels.write()
        time.sleep(0.01)

Does what I would expect