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

Add argument to control brightness #4815

Closed
wants to merge 1 commit into from

Conversation

singhkpratham
Copy link

@singhkpratham
Copy link
Author

Hi @dpgeorge , please have a look into this and accept/reject

@dpgeorge
Copy link
Member

Thanks for the contribution. For a previous attempt at something similar see #3623.

I would be inclined not to merge this code. The main reason is that it will slow down the driver for all users even when the brightness feature is not used. Instead it would probably be more efficient to compute the dimmed colour outside this driver and pass in already-dimmed values (you could also do other colour manipulations this way). Eg:

def dim_colour(c, brightness):
    return tuple(int(round(v * brightness)) for v in c)
red = dim_colour((255, 0, 0), 0.5)
for i in range(8):
    np[i] = red

An alternative would be to create a new class that has a brightness option, eg:

class NeoPixelDim:
    def __init__(self, pin, n, brightness=0.5, bpp=3, timing=1):
        super().__init__(pin, n, bpp, timing)
        self.brightness = brightness
    def __setitem__(self, index, val):
        super().__setitem__(index, int(round(v * brightness)) for v in c)

@peterhinch
Copy link
Contributor

I agree. The class should, of course, read

class NeoPixelDim(NeoPixel):
    def __init__(self, pin, n, brightness=0.5, bpp=3, timing=1):
        super().__init__(pin, n, bpp, timing)
        self.brightness = brightness
    def __setitem__(self, index, val):
        super().__setitem__(index, int(round(v * brightness)) for v in c)

@dpgeorge
Copy link
Member

The class should, of course, read ...

Yes indeed, it should derive from NeoPixel.

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.

None yet

3 participants