Skip to content

control global brightness on APA102 (and other chip supporting it) #91

Closed

Description

@avilleret

I saw the brightness is fixed to 0xFF in https://github.com/FastLED/FastLED/blob/master/chipsets.h#L141

This could be very useful to control the global brightness of chips that has one (like APA102).

Cheers

Activity

  1. focalintent commented on Oct 30, 2014

    @focalintent
    Contributor

    Still thinking about a good way to expose it in the library API - noodling on a couple of ideas.

    For now I'm leaving it max'd for folks doing POV beings you start getting visible stutter/flickering as soon as you start scaling that brightness down.

  2. avilleret commented on Oct 30, 2014

    @avilleret
    Author

    I understood the need to set it to max for POV application, and I can fade it down by hacking the APA102Controller class declaration (but it's ugly :-) )

    I see two ways to start :

    • use the alpha channel of ARGB
    • add a brightness member to CLEDController class and a setter method to control brightness on chips that support it.
  3. focalintent commented on Oct 30, 2014

    @focalintent
    Contributor

    ARGB is not officially supported yet - and this isn't an A(lpha) channel thing. It is more likely going to be something that is used as part of 16-bit RGB values (as a precursor to dithering).

    I'm also very cautious about adding arbitrary methods to the controllers - especially when it is something i'm going to have to support/document - so, rather than rushing something in, i'm happy to let people that know about it adjust the value directly in the header file

  4. focalintent commented on Apr 5, 2015

    @focalintent
    Contributor

    Leaving this as it is for now.

  5. avilleret commented on Dec 17, 2015

    @avilleret
    Author

    hey,

    what is the status of this issue ? it has been closed to let it "as it is" but later tagged with "FastLED 3.1 release"
    Since 3.1 is out now, I would like to know if the global brightness of APA102 (and other) is accessible (and easily modifiable), I didn't see anything related to in the release note, nor in the code.
    I really need to control it on the fly during the show, so an hard coded value in chipset.h is not a solution for me.
    Thanks for your work.

  6. focalintent commented on Dec 17, 2015

    @focalintent
    Contributor

    The milestone adjustment was part of a bulk tagging. I never put something in for global brightness control of the APA102 because a) i couldn't put together a good interface that I was happy enough with and b) I hated the effect of using the brightness adjustment and there wasn't a good/fast reliable way to use it with the global brightness.

    https://gist.github.com/focalintent/919fc68b365668dbfda9 has a rough outline of a modified custom class that exposes this and how you'd use it - so you can use it for your project.

    If you need to be able to adjust it on a per-pixel basis, that's a fair bit more complexity to deal with (as far as fitting in with the rest of the infrastructure/architecture).

  7. avilleret commented on Dec 18, 2015

    @avilleret
    Author

    thanks a lot for this class example !
    I have to modify it a little bit to make it work.
    Here is my version : https://gist.github.com/avilleret/e84628188a85330bc660

    Btw, as far as I understand, there is no chance to see that code included in FastLED one day.
    I think it's a shame, but it's your choice.

    Thanks again for giving me such support and code example.

  8. focalintent commented on Dec 18, 2015

    @focalintent
    Contributor

    I don't like the idea of users generally using the led controller objects directly - so this isn't a good general solution.

    Also - it is important that the first three bits in an apa102 pixel data be high - or else data will get skipped.

    That was why I was doing the mask with 0xE0 (force the top three bits to be high). The global brightness should then be a value from 0-31.

  9. avilleret commented on Dec 18, 2015

    @avilleret
    Author

    thanks for the review, btw, I uploaded the wrong file, now it should be ok.
    in yours, only the writeLed() method is using the bBaseValue and not the show() methods.
    I've fixed that.

  10. embedded-creations commented on Jan 6, 2016

    @embedded-creations
    Contributor

    I just got some APA102s with the intention of using global brightness control to get pseudo 15-bit color out of the LEDs. I made a simple demo that increments/decrements a 16-bit value, and see lots of stepping at slow increments of low values with the normal 8-bit APA102, but it's really smooth when I use the GBC bits. I'll make a better demo and share with the FastLED community.

    @focalintent I'm concerned by your comment of "I hated the effect of using the brightness adjustment", are you sensitive to the >500 Hz PWM? Tim commented on that too on his blog, but I'm just not seeing anything bothersome.

  11. kasperkamperman commented on Jan 6, 2016

    @kasperkamperman

    @embedded-creations interesting. Do you have some demo code and/or video online? I'm using dithering to prevent stepping on slow increments of low values, but this seems like an option that might be worthwhile to test.

  12. embedded-creations commented on Jan 6, 2016

    @embedded-creations
    Contributor

    The code's a mess, I just hacked something together last night starting from the Adafruit DotStar library. Here's the interesting part:

      uint8_t globalbrightness;
      uint8_t localbrighteness;
    
      if(value & 0x8000) {
        globalbrightness = 0x1F;
        localbrighteness = value >> 8;
      } else if(value & 0x4000) {
        globalbrightness = 0x10;
        localbrighteness = value >> 7;
      } else if(value & 0x2000) {
        globalbrightness = 0x08;
        localbrighteness = value >> 6;
      } else if(value & 0x1000) {
        globalbrightness = 0x04;
        localbrighteness = value >> 5;
      } else if(value & 0x0800) {
        globalbrightness = 0x02;
        localbrighteness = value >> 4;
      } else {
        globalbrightness = 0x01;
        localbrighteness = value >> 3;
      }
    
      strip.sw_spi_out(0xE0 | globalbrightness);                //  Pixel start with global brightness
      strip.sw_spi_out(0x00); // R,G,B
      strip.sw_spi_out(localbrighteness);
      strip.sw_spi_out(0x00);
    
  13. focalintent commented on Jan 6, 2016

    @focalintent
    Contributor

    Where this gets ugly is when you have non zero values for more than just one of r, g, or b :)

  14. embedded-creations commented on Jan 6, 2016

    @embedded-creations
    Contributor

    Yeah, I was thinking bitwise-OR the three colors, and use that as "value", shift all three colors by the same amount.

  15. embedded-creations commented on Jan 6, 2016

    @embedded-creations
    Contributor

    Here's a simple demo:
    https://github.com/embedded-creations/apa102-gbctest

    The code interpolates between two random colors very slowly. Even with a brightness of 10/256, stepping is not very apparent on the LED using GBC bits, but it is very apparent on the 8-bit LED. Interpolation code is from the blink1 firmware, modified to work with 16-bit colors instead of 8-bit. I ran this on a Teensy 3.1 at 72MHz but it's not really platform specific.

  16. embedded-creations commented on Jan 9, 2016

    @embedded-creations
    Contributor

    Did anyone give the demo code a try? I'm curious what you guys think. Do you notice the PWM dimming?

    @focalintent This issue was closed 8 months ago, is it worth reopening the topic as there is interest?

  17. focalintent commented on Jan 9, 2016

    @focalintent
    Contributor

    Not so much in this issue - more likely what i'd do is either roll it in as part of a move to a 16-bit rgb(w) world, or try juggling what you've done to work with the existing brightness scaling - either way, it's unlikely that I'd ever expose a direct api for setting the brightness on a per pixel (or even really per-strip) value.

    The other thing that I'd want to make sure of is that I did not slow down the APA102 output by adding extra overhead. On something like a teensy this work wouldn't be that much extra - but on avr it could pull back the performance of prepping/writing out data (in which case, I'd also want a good way to shut it off easily).

    (I haven't had a chance to give the demo a try yet, though -- combination of day job, a contract that I'm trying to finish off, and still neck deep in some library internals re-architecting - and somewhere in there my brain demands sleep)

  18. embedded-creations commented on Jan 10, 2016

    @embedded-creations
    Contributor

    more likely what i'd do is either roll it in as part of a move to a 16-bit rgb(w) world, or try juggling what you've done to work with the existing brightness scaling - either way, it's unlikely that I'd ever expose a direct api for setting the brightness on a per pixel (or even really per-strip) value.

    I agree with you. There's not much value to this unless you're using 16-bit math, or applying a gamma/color correction behind the scenes (like the SmartMatrix Library does) and mapping 8-bit RGB onto the 13-bit space.

    No pressure on trying anything, I just don't want this topic to be forgotten as it's in a closed issue. Should I create a new issue for it?

  19. focalintent commented on Jan 11, 2016

    @focalintent
    Contributor

    Nah - it's already part of the giant offline list i'm keeping for the 16-bit re-write of the library :)

  20. dimitre commented on Apr 29, 2017

    @dimitre

    I'm now testing the brand new apa102 2020, 198 leds per meter (beautiful) and got myself questioning the same. it has a sharp curve to black when using global brightness, and it would be great being able to control independent brightness as a parameter too (optionally).

    Today I've made some proof of concept using this library, of course it doesn't have the amazing capabilities of FastLED
    https://github.com/pololu/apa102-arduino
    and I could make a great smooth gradient to black dimming the color and global brightness at the same time.

    #include <APA102.h>
    #define NUM_LEDS 198
    
    rgb_color leds[NUM_LEDS];
    
    APA102<7, 14> ls1;
    APA102<10, 13> ls2;
    APA102Base * ledStripArray[] = { &ls1, &ls2 };
    
    void setup() {
    }
    
    int contagem = 0;
    
    void loop() {
      ls1.startFrame();
      for (int a = 0; a < NUM_LEDS; a++) {
        float brilho = sin(a / 10.0 + contagem / 10.0) * 16.0 + 16.0;
        ls1.sendColor(rgb_color(brilho * 8, brilho * 8, 0), brilho);
      }
    
      ls1.endFrame(NUM_LEDS);
      contagem++;
      // put your main code here, to run repeatedly:
    }
  21. extesy commented on Sep 15, 2018

    @extesy
    Contributor

    @avilleret @focalintent I've created a pull request #653 to add global brightness support.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions