Brownout avoidance

I’m having some issues whereby if I power the matrix and PCB from the USB port, and draw too many bright pixels, I’ll get a brownout.

FastLED has a feature where you can set a power limit, and it scans the pixel array and does a power draw calc, then scales total brightness back to compensate.

I could do this manually each frame, but wondering if there’s any support I’ve overlooked or if its been done before!

Sorry, no, this feature doesn’t exist

Experimentally, I came up with these values that get me close. Then I scale brightness back enough to hit the power budget. Of course it’s important to do this BEFORE you flip the back buffer :slight_smile:

// EstimatePowerDraw
//
// Estimate the total power load for the board and matrix by walking the pixels and adding our previously measured
// power draw per pixel based on what color and brightness each pixel is

int EstimatePowerDraw()
{
    constexpr auto kBaseLoad       = 1500;          // Experimentally derived values
    constexpr auto mwPerPixelRed   = 4.10f;
    constexpr auto mwPerPixelGreen = 0.82f;
    constexpr auto mwPerPixelBlue  = 1.75f;

    float totalPower = kBaseLoad;
    for (int i = 0; i < NUM_LEDS; i++)
    {
        const auto pixel = leds[i];
        totalPower += pixel.r * mwPerPixelRed   / 255.0f;
        totalPower += pixel.g * mwPerPixelGreen / 255.0f;
        totalPower += pixel.b * mwPerPixelBlue  / 255.0f;
    }
    return (int) totalPower;
}