adafruit / Adafruit_CircuitPython_NeoPixel

CircuitPython drivers for neopixels.
MIT License
304 stars 98 forks source link

Pixel buffer accepts tuples but returns lists with different value #71

Closed eddiewebb closed 4 years ago

eddiewebb commented 4 years ago

On version 4.1.0

color values passed as tuples (r,g,b) are returned as `[brightnessr,brightnessb,brightness*c]

import board
import neopixel 
color_red=(80,0,0)      
self.pixels = neopixel.NeoPixel(board.D18, 256, auto_write=False, brightness=0.5)
red = (80,0,0)
pixels[1] = red
print( pixels[1])

Prints [40,0,0]

eddiewebb commented 4 years ago

Not sure why the list/tuple change. But change in value is from https://github.com/adafruit/Adafruit_CircuitPython_NeoPixel/blob/master/neopixel.py#L232 which multiplies by brightness.

caternuson commented 4 years ago

Can you post full code so we can also see how you initialized the NeoPixel object.

tannewt commented 4 years ago

What version of the library are you using?

eddiewebb commented 4 years ago

@caternuson, the code is in a public repo. You can see where I define colors as tuples https://github.com/eddiewebb/sense-show/blob/master/led_strip.py#L22

And where I basically want to say "if the pixel is not already set to X, set it to Y". That call returns the color as a list. https://github.com/eddiewebb/sense-show/blob/master/led_strip.py#L133

@tannewt 4.1.0

sudo pip3 freeze | grep neopixel
adafruit-circuitpython-neopixel==4.1.0

You can see I've worked around the tuple/list issue by converting the response from neopixel. https://github.com/eddiewebb/sense-show/blob/master/led_strip.py#L138

now = self.pixels[id]
if isinstance(now, list):
    now = tuple(int(i*(1/brightness)) for i in now)
caternuson commented 4 years ago

I think you might be hitting this: https://github.com/adafruit/Adafruit_CircuitPython_Pypixelbuf/pull/4#discussion_r368309515 which should be fixed in latest release. Try updating to the 5.0.0 release and see if the problem persists: https://github.com/adafruit/Adafruit_CircuitPython_NeoPixel/releases/tag/5.0.0 Return may still be a list, but hopefully will not have the incorrect value.

kattni commented 4 years ago

This issue is resolved.

>>> import board
>>> import neopixel
>>> pixels = neopixel.NeoPixel(board.NEOPIXEL, 10, auto_write=False, brightness=0.5)
>>> red = (80, 0, 0)
>>> pixels[1] = red
>>> print(pixels[1])
(80, 0, 0)