Arduino+ws2811 and the gamma issue.

  • Hi, i'm finally playing with hyperion and a ws2811 led strip.


    I'm using PC -> Arduino+fastled (adalight) -> led strip.


    After i configured the gamma ramp, i'm facing the problem that the lower btightness appears just black.
    So i documented myself and i've found that the fastled library actually implements temporal dithering, but the way it does it is not directly accessible by hyperion, because, as stated here:


    I'm using a sketch from here, and in the code i read the following:


    Code
    leds[i].r = r;
        leds[i].g = g;
        leds[i].b = b;
      }
      // shows new values
    FastLED.show();


    ...but what if we do something like this:


    Code
    //imagine we want to show a perfect gray (127,127,127)
       leds[i].r = 255;
       leds[i].g = 255;
       leds[i].b = 255;
    FastLED.setBrightness(127);
    FastLED.show();


    Basically, my idea is to stretch the luma component to full range, and then call setBrightness accordingly to scale them down so that the fastled temporal dithering would kick in.
    I suppose we also need to add FastLED.delay() into the sketch main loop (it is not clear to me if it needs to be done or not)


    Q: "Why don't you test it by yourself?"
    A: "Because i will be back at home in a month, and i just have had this idea :)"


    What do you think? would it work?

  • The following works:




    What one should expect from the code above is to gain more precision at lower brightness, NOT better color fidelity.
    In fact, you actually lose the ability to set different gamma values for r,g,b.

    So, a dark color will appear dithered (better), but a color like this: 255,255,1 would not gain anything; this is because FastLed library does not provide different brightness per channel, just a global one; that means that 255,255,1 wil still be reproduced (after applying gamma) as 255,255,0.


    You will notice that gamma correction is done inside the sketch (#define Gamma 2.6), and it is done using float values; this is needed to gain extra precision (or hyperion would just cut it to integer).


    What the code does:
    1 reads the color to display, and compute its gamma and store it in float.
    2 Find the maximum value and use it as the master brightness factor
    3 stretch/normalize the color to full range/brightness
    4 display


    That way, the FastLed dithering should work; one thing i'm not 100% sure is still where to put FastLED.delay.
    By now i've put it inside the main waitloop, and it will wait/dither in 16ms steps; this means that arduino will see if there is data available on the serial every 16ms; this could introuduce some lag (well...16ms is not that much).


    I hope to receive some code review ;)

Jetzt mitmachen!

Sie haben noch kein Benutzerkonto auf unserer Seite? Registrieren Sie sich kostenlos und nehmen Sie an unserer Community teil!