-
-
Save tdicola/6fe1fbc173dcd49de3a95be5fd9594f6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# NeoPixel driver for MicroPython on ESP8266 | |
# MIT license; Copyright (c) 2016 Damien P. George | |
from esp import neopixel_write | |
class NeoPixelRGBW: | |
def __init__(self, pin, n): | |
self.pin = pin | |
self.n = n | |
self.buf = bytearray(n * 4) | |
self.pin.init(pin.OUT) | |
def __setitem__(self, index, val): | |
r, g, b, w = val | |
self.buf[index * 4] = g | |
self.buf[index * 4 + 1] = r | |
self.buf[index * 4 + 2] = b | |
self.buf[index * 4 + 3] = w | |
def __getitem__(self, index): | |
i = index * 4 | |
return self.buf[i + 1], self.buf[i], self.buf[i + 2], self.buf[i + 3] | |
def fill(self, color): | |
r, g, b, w = color | |
for i in range(len(self.buf) / 4): | |
self.buf[i * 4] = g | |
self.buf[i * 4 + 1] = r | |
self.buf[i * 4 + 2] = b | |
self.buf[i * 4 + 3] = w | |
def write(self): | |
neopixel_write(self.pin, self.buf, True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import machine | |
import math | |
import neopixelw | |
import time | |
PIXEL_WIDTH = 8 | |
PIXEL_HEIGHT = 5 | |
MAX_BRIGHT = 100.0 | |
np = neopixelw.NeoPixelRGBW(machine.Pin(15), PIXEL_WIDTH*PIXEL_HEIGHT) | |
# Clear all the pixels and turn them off. | |
np.fill((0,0,0,0)) | |
np.write() | |
while True: | |
np.fill((0,0,0,0)) | |
current = time.ticks_ms() / 1000.0 | |
for x in range(PIXEL_WIDTH): | |
for y in range(PIXEL_HEIGHT): | |
v = 0.0 | |
v += math.sin(x+current) | |
v += math.sin(1.0*(x*math.sin(current/0.5)+y*math.cos(current/0.25))+current) | |
cx = x + 0.5*math.sin(current/5.0) | |
cy = y + 0.5*math.cos(current/3.0) | |
v += math.sin(math.sqrt((math.pow(cx, 2.0)+math.pow(cy, 2.0))+1.0)+current) | |
v = (v+3.0)/6.0 | |
r = math.sin(v*math.pi) | |
g = math.sin(v*math.pi+2.0*math.pi/3.0) | |
b = math.sin(v*math.pi+4.0*math.pi/3.0) | |
#w = math.sin(v*math.pi+6.0*math.pi/3.0) | |
np[y*PIXEL_WIDTH+x] = (int(MAX_BRIGHT*r),int(MAX_BRIGHT*g),int(MAX_BRIGHT*b),0) | |
np.write() |
is there a way for getting this working with the neopixel module in Circuit Python 0.9.1 on the ESP8266.
np = neopixel.NeoPixel(board.GPIO15, PIXEL_WIDTH*PIXEL_HEIGHT)
Traceback (most recent call last):
File "", line 1, in
File "neopixel.py", line 15, in init
AttributeError: 'Pin' object has no attribute 'init'
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Don't you want those rgb values to the absolute values or am I missing something?