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

How to control the brightness of the entire strip #3

Open
kaitlynlandmesser opened this issue Jan 22, 2019 · 1 comment
Open

How to control the brightness of the entire strip #3

kaitlynlandmesser opened this issue Jan 22, 2019 · 1 comment

Comments

@kaitlynlandmesser
Copy link

kaitlynlandmesser commented Jan 22, 2019

Do you know of a simple way to decrease the brightness with Swift? Like setBrightness(uint8_t b) in the Arduino code.

Thanks!

@uraimo
Copy link
Owner

uraimo commented Jan 22, 2019

Hi! Considering how extremely bright these leds tend to be I guess that a lot of people will wonder the same thing, thanks for asking.

The RGB value we are setting actually selects the brightness level of one of the three R,G,B independent components that make up each single WS2812 led (from 0-255, with 0 the single component is barely visible, with 255 it has maximum blinding brightness), and that's the only thing that can be controlled.
What the Arduino library does behind the scenes to implement overall brightness, is to store a 0-255 brightness value when setBrightness() is called and then using it to scale the RGB value you set:

r = (r * brightness) >> 8;

So, selecting a pure red (255-0-0) with 25% brightness (setBrightness(63)), the value used to configure the strip will actually be 63-0-0. Configuring this value manually without touching the brightness would give you the same result.
Since the library continuously reconfigures the strip with the last selected sequence of colors over and over (same as this library), when you change the brightness this sequence is updated with the new values to be displayed.

The first prototypes of this library had the same thing, but it was later removed since the result is not really convincing (ramping up from 0 to 255 the light is not perceived to increase as smoothly as it should for lack of proper gamma correction) and because as explained above it requires hidden changes to the value selected by the user just to deliver subpar results.

I just thought that those who needed to alter the brightness would have just implemented scaling manually on their RGB values doing a color_component=(color_component*brightness)/255 for each one of the RGB components right before setting the value with one of the setLed functions.

But now that I take another look at this, implement brightness w/ gamma correction (1,2) and see how it looks on a couple of strips could be a good idea :)

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

2 participants