Skip to content
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

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

Closed
eddiewebb opened this issue Jan 27, 2020 · 6 comments
Closed

Comments

@eddiewebb
Copy link

eddiewebb commented Jan 27, 2020

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 eddiewebb changed the title Pixel buffer accepts tuples but returns lists Pixel buffer accepts tuples but returns lists with different value Jan 27, 2020
@eddiewebb
Copy link
Author

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
Copy link
Contributor

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

@tannewt
Copy link
Member

tannewt commented Jan 27, 2020

What version of the library are you using?

@eddiewebb
Copy link
Author

eddiewebb commented Jan 27, 2020

@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
Copy link
Contributor

I think you might be hitting this:
adafruit/Adafruit_CircuitPython_Pypixelbuf#4 (comment)
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
Copy link
Contributor

kattni commented May 4, 2020

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)

@kattni kattni closed this as completed May 4, 2020
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

No branches or pull requests

4 participants