Displayotron Hat - bar LEDS


#1

There only appears to be set_graph(value) implemented for the bar of leds, wanted to know how to modify that to set_graph(value,max_brighness=MAX) where max is whatever the max int brightness for each led is

as it would have a default parameter of max_brighness=MAX then would work as it used to if that parameter not passed, but to me the bar leds are way to bright and I’d like to try them at MAX/2 or MAX/3 for a volume indicator.

I know set_graph is quite cool and varies brightness of top LED based on fraction of that LEDs brightness depending on remainder.

so essentially cap each led at max_brightness before it moves up to next one.

or actually implement the set_bar function would be an alternative, that just has pass at the moment.


#2

It’s been a while since I implemented the slightly crazy code that makes it possible to display a bargraph on the captouch LEDs. They’re not individually PWM controlled, so the code to make the appear so is a little contrived, see:

What’s actually happening is that only the LED on the very edge of the bargraph is brightness controlled. The rest of the LEDs are all off, or 0%, with some trickery used on the polarity bit to make them on or 100%

Global duty settings: off = 0%, on = 50%

            LED1   LED2   LED3   LED4   LED5   LED6
State:      0      0      0      1      0      0
Polarity:   1      1      1      0      0      0
Result:     100%   100%   100%   50%    0%     0%

You can only have either off (0%). NOT off (100%). Or on (50%) at the predetermined global brightness setting.

  • off = LED is off, with no polarity change
  • on = LED is off, with polarity change to make it on
  • other = LED is on, and takes the global brightness setting for on state

You could drop the polarity fiddling, and the smooth transition at the edge of the bargraph so you just have OFF and on with whatever brightness you like (out of the 16 levels). It wouldn’t look as nice, but if you reduce the brightness then those 16 levels of transition are going to be crunched anyway.


#3

sounds like what I want, whats the parameter/binary-encoding that sets “full on” brightness level?.


#4

You might get away with:

def set_graph(percentage):
    """Light a number of bargraph LEDs depending upon value
    :param hue: hue value between 0.0 and 1.0
    """

    cap._write_byte(cap1xxx.R_LED_DIRECT_RAMP, 0b00000000)
    cap._write_byte(cap1xxx.R_LED_BEHAVIOUR_1, 0b00000000)
    cap._write_byte(cap1xxx.R_LED_BEHAVIOUR_2, 0b00000000)

    # The Cap 1xxx chips do *not* have full per-LED PWM
    # brightness control. However...
    # They have the ability to define what on/off actually
    # means, plus invert the state of any LED.

    total_value = STEP_VALUE * NUM_LEDS
    actual_value = int(total_value * percentage)
    set_state = 0b00000000

    on_brightness = 8 # Valid range: 0 (off) to 15 (max)

    for x in range(NUM_LEDS):
        if 0 < actual_value:
            set_state |= 1 << (NUM_LEDS - 1 - x)
        actual_value -= STEP_VALUE

    cap._write_byte(cap1xxx.R_LED_DIRECT_DUT, on_brightness << 4)
    cap._write_byte(cap1xxx.R_LED_POLARITY, 0b11111111)
    cap._write_byte(cap1xxx.R_LED_OUTPUT_CON, set_state)