Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 11 of 11

Thread: OctoWS2811 Help on Controlling Brightness

  1. #1
    Junior Member
    Join Date
    Dec 2013
    Location
    Santa Clara
    Posts
    10

    OctoWS2811 Help on Controlling Brightness

    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.

  2. #2
    Senior Member Wozzy's Avatar
    Join Date
    Jan 2013
    Location
    Philadelphia, Pennsylvania USA
    Posts
    344
    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.

  3. #3
    Junior Member
    Join Date
    Dec 2013
    Location
    Santa Clara
    Posts
    10
    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.

  4. #4
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,169
    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.

  5. #5
    Senior Member mortonkopf's Avatar
    Join Date
    Apr 2013
    Location
    London, uk
    Posts
    898
    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 by mortonkopf; 03-03-2014 at 05:40 PM.

  6. #6
    Senior Member
    Join Date
    Jan 2013
    Posts
    966
    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.
    Click image for larger version. 

Name:	brightness_perception.png 
Views:	379 
Size:	5.0 KB 
ID:	1553
    Last edited by Headroom; 03-03-2014 at 05:58 PM.

  7. #7
    Junior Member
    Join Date
    Dec 2013
    Location
    Santa Clara
    Posts
    10
    Quote Originally Posted by PaulStoffregen View Post

    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?

  8. #8
    Senior Member Wozzy's Avatar
    Join Date
    Jan 2013
    Location
    Philadelphia, Pennsylvania USA
    Posts
    344
    (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 by Wozzy; 03-03-2014 at 07:20 PM.

  9. #9
    Junior Member
    Join Date
    Dec 2013
    Location
    Santa Clara
    Posts
    10
    Quote Originally Posted by Wozzy View Post
    (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.

  10. #10
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,169
    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.

  11. #11
    Junior Member
    Join Date
    Dec 2013
    Location
    Santa Clara
    Posts
    10
    Thanks! I totally see that it really isn't too much of a difference or difficult now with the OctoWS2811 library.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •