Thanks to visit codestin.com
Credit goes to github.com

Skip to content

On-board NeoPixels max brightness when brightness is set to 0 #3753

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
kattni opened this issue Nov 24, 2020 · 2 comments · Fixed by #3917
Closed

On-board NeoPixels max brightness when brightness is set to 0 #3753

kattni opened this issue Nov 24, 2020 · 2 comments · Fixed by #3917

Comments

@kattni
Copy link

kattni commented Nov 24, 2020

Tested on MagTag, PyBadge, CPX and QT Py. The issue is not present on QT Py which requires adafruit_pypixelbuf. It is present on all other boards, which may narrow it down to an issue in _pixelbuf.

Used simple code that uses board.NEOPIXEL to turn the pixels red, and then tested brightness:

  • Setting brightness = 0 makes the on-board NeoPixels max brightness. They are the appropriate color when this occurs (as in they are not getting incorrect color info).

  • Setting brightness = 0.1 makes them dim.

  • Setting brightness = 0.0 shuts them off, though that's likely because it thinks it's something like 0.000000001 and they're not actually "off" but the LEDs or human eyes can't handle that level of dimness.

@brrzap
Copy link

brrzap commented Jan 1, 2021

i can reproduce this using a custom build on a QT Py that adds the native _pixelbuf. it does not occur using brightness=0 in the constructor:

import board
import neopixel
np = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0)
# no change visible yet
np[0] = (100,0,0)  
# now turned off
np.brightness = 0
# back to full on

looking in shared-bindings/_pixelbuf/PixelBuf.c, the constructor calls mp_obj_get_float(), while the setter uses mp_obj_float_get(). this skips ..._get_float()'s extra error-checking that seems to catch this case for the constructor. i can't follow the bitmath in mp_obj_float_get() to prove the fault, but testing shows that the setter takes the brightness > 1 fork after it's called.

changing the setter to use mp_obj_get_float() instead of mp_obj_float_get() does seem to fix the error, but it will add some cycles. changing the bitmath might be another option but i don't have any suggestions as to how.

@ladyada
Copy link
Member

ladyada commented Jan 1, 2021

@brrzap good catch, wanna submit a PR for that setter change? its ok if it adds some cycles - better to have it right :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants