OctoWS2811 Help on Controlling Brightness

Status
Not open for further replies.
Hi Everyone,

I tried looking around the forum for a way to control the brightness using the OctoWS2811 library and I wasn't able to find anything.

I know Adafruit's NeoPixel library has brightness control from the code, but how do you adjust the brightness for the OctoWS2811 library and the Teensy 3.1?
The LEDs are too bright to look at.

Any guidance or help is much appreciated.
 
If your setting the colors manually, just use RGB values less than 255.
If your setting the colors with HSL values (Hue Saturation Lightness), adjust the lightness value down.
Note that human color perception is logarithmic, so half the value doesn't appear half as bright.
 
Thanks for the quick response. I'll look into what you said. Any particular example how to do that in the code as I am new to how this library does this...? I'm a noob at the code.

It needs to be done for the entire display. I still wasn't able to find it in the library FYI.

Thanks again.
 
There is no single function to globally control the brightness of all the pixels.

But every pixel is controlled by a 24 bit color number. Red, green and blue range from 0 to 255, with 255 being the brightest. If you want the entire display be less bright, simply use less of the range, like perhaps 0 to 80 or even 0 to 50.

The WS2811 / WS2812 / WS2812B pixels are very simple devices designed for the lowest possible cost. They do not have any sort overall brightness control. They only have the 24 bit color control. They simply do not have any way to redefine how bright 255 is. Their design is fixed, so your only option is to simply use less of the 0 to 255 range.
 
I am using something similar for an led array that is used both in the daytime and the night, and it is too bright in the night. One other way that you can do this, if not using HSL and you want to manipulate the whole array, You can objectify a brightness value to apply to the sketch by using a helper function. This example below is simplified for if you are receiving your colour values as rgb input. This would work in two parts:

firstly, so that you can just use any value into a fixed value for brightness for all leds:
Code:
float brightness = 40;   //should be value between 1-255, or can be a value received from another function//

//--------Brightness HELPER FUNCTION-----------//
float scale = brightness/255;

secondly, use the colour helper function that this relates to:
Code:
//-------Colour HELPER FUNCTION------//
// Create a 24 bit color value from R,G,B ////these strips are BRG, but you might need to change this
unsigned int Color(byte b, byte r, byte g)
{
  b = b*scale;g=g*scale;r=r*scale;
  //Take the lowest 8 bits of each value and append them end to end
return( ((unsigned int)r & 0xFF )<<16 | ((unsigned int)g & 0xFF)<<8 | (unsigned int)b & 0xFF);
  }

in your code you could then use the Color function such as:
Code:
 leds.setPixel(i, Color(255,0,0));//B-R-G

so, I know that it isn't needed as written i.e. 255,0,0, but but if you had a loop getting rgb values and pasting then into a buffer, and that buffer was then accessed by the loop with the 'Color' function, you get your brightness output, like Color(x,y,z), where x,y,and z are objects. This way you can input original colours quickly from different sources, without looking into changing individual values.
Also (but I have not tried it yet) you should be able to make the brightness float receive a value from an external source (perhaps an analogue input from a 'brightness dial'.
note that as wozzy pointed out, this is not a straight linear relationship.
 
Last edited:
The relationship between PWM regulated RGB values and luminance is mostly linear.
The relationship between luminance and brighness follows the CIE lab curve. A logarithmic curve is a coarse approximation although propably sufficient for this exercise.
Usually correlating brightness values are stored in a look up table so real-time calculation with coputationally expensive float variables can be avoided.
brightness_perception.png
 
Last edited:
But every pixel is controlled by a 24 bit color number. Red, green and blue range from 0 to 255, with 255 being the brightest. If you want the entire display be less bright, simply use less of the range, like perhaps 0 to 80 or even 0 to 50.

The WS2811 / WS2812 / WS2812B pixels are very simple devices designed for the lowest possible cost. They do not have any sort overall brightness control. They only have the 24 bit color control. They simply do not have any way to redefine how bright 255 is. Their design is fixed, so your only option is to simply use less of the 0 to 255 range.

Hi Paul,

Thanks for the detailed response. So if when I adjust the brightness on the RGB scale value 0-255, doesn't that actually affect the color output as well with respect to brightness? So if I wanted a lesser bright red, wouldn't the color red (255, 0, 0) not be as much as a true red? And what about the issue of gamma correction with respect to brightness as well? Does the WS2812/Bs suffer from this as well?
 
(R, G, B)
(255,0,0) Max Bright Red
(0,255,0) Max Bright Green
(0,0,255) Max Bright Blue
(128,0,0) Mid Bright Red
(16,0,0) Dim Red
(255,255,255) Max Bright White
(128,128,128) Mid Bright White
(16,16,16) Dim White
(2,2,2) Barely-on white
(0,0,0) OFF
...
 
Last edited:
(R, G, B)
(255,0,0) Max Bright Red
(0,255,0) Max Bright Green
(0,0,255) Max Bright Blue
(128,0,0) Mid Bright Red
(16,0,0) Dim Red
(255,255,255) Max Bright White
(128,128,128) Mid Bright White
(16,16,16) Dim White
(2,2,2) Barely-on white
(0,0,0) OFF
...


Thanks! I pretty much get it. It's a little different than the NeoPixel library that I'll have to get used to it.
 
Inside the NeoPixel library, all it's doing is this:

Code:
    if(brightness) { // See notes in setBrightness()
      r = (r * brightness) >> 8;
      g = (g * brightness) >> 8;
      b = (b * brightness) >> 8;
    }

If you've used their setBrightness() function, it's just multiplying every color by that number and dividing by 256.
 
Status
Not open for further replies.
Back
Top