Skip to content

esp8266/scripts/: Add fill() to NeoPixel #2033

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

mcauser
Copy link
Contributor

@mcauser mcauser commented May 6, 2016

Added a reset() method to the NeoPixel driver, for quickly clearing the buffer.
I am not sure if redefining self.buf as a new bytearray() is the most efficient pattern.

a) Replace buffer:

self.buf = bytearray(self.n * 3)

vs b) loop and set each:

for i in range(np.n):
    np[i] = (0,0,0)

Complete example

from machine import Pin
from neopixel import NeoPixel
pin = Pin(5, Pin.OUT)
np = NeoPixel(pin, 8)
np[0] = (255, 0, 0)
np[1] = (0, 255, 0)
np[2] = (0, 0, 255)
np.write()
...
np.reset()
np.write()

@dpgeorge
Copy link
Member

dpgeorge commented May 6, 2016

I'd suggest looping and setting, but something like:

for i in range(len(self.buf)):
   self.buf[i] = 0

Alternatively you can call it clear(), or even fill(col) to fill with a generic colour.

@mcauser
Copy link
Contributor Author

mcauser commented May 6, 2016

Thanks for the feedback @dpgeorge . I updated it to be fill(color) as it's more useful.

import utime
from machine import Pin
from neopixel import NeoPixel
pin = Pin(5, Pin.OUT)
np = NeoPixel(pin, 8)

red = (16,0,0)
green = (0,16,0)
blue = (0,0,16)
cyan = (0,16,16)
magenta = (16,0,16)
yellow = (16,16,0)
black = (0,0,0)
colors = [red,green,blue,cyan,magenta,yellow,black]

for color in colors:
    np.fill(color)
    np.write()
    utime.sleep_ms(1000)

Newer NeoPixel strips and sticks are shipping with 5050 RGBW LEDs. This driver will need to be updated to 4 bytes per colour per pixel at some stage.

@mcauser mcauser changed the title esp8266/scripts/: Add reset() to NeoPixel esp8266/scripts/: Add fill() to NeoPixel May 6, 2016
@pfalcon
Copy link
Contributor

pfalcon commented May 7, 2016

Merged, thanks.

@pfalcon pfalcon closed this May 7, 2016
@mcauser mcauser deleted the neopixel branch March 12, 2017 05:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants