FastLED 3.9.15
Loading...
Searching...
No Matches

◆ getEstimatedPowerInMilliWatts()

fl::u32 CFastLED::getEstimatedPowerInMilliWatts ( bool apply_limiter = true) const

Get estimated power consumption in milliwatts.

Calculates the estimated power consumption based on current LED buffer contents, brightness setting, and configured power model. This provides visibility into power usage for monitoring and debugging.

Parameters
apply_limiterIf true (default), applies power limiting to calculate actual power. If false, returns requested power before limiting.
Returns
Estimated LED power consumption in milliwatts:
  • apply_limiter=true: Power AFTER applying max-power cap (actual power)
  • apply_limiter=false: Power BEFORE limiting (requested power)
Note
Usage examples:
fl::u32 actual = FastLED.getEstimatedPowerInMilliWatts(); // With limiting (default)
fl::u32 requested = FastLED.getEstimatedPowerInMilliWatts(false); // Without limiting
CFastLED FastLED
Global LED strip management instance.
When apply_limiter=true:
  • If power limiting is NOT enabled, returns unrestricted power
  • If power limiting IS enabled, returns power after brightness reduction
MCU power consumption is NOT included in this calculation. Add your platform-specific MCU power separately:
fl::u32 mcu_power_mW = 25 * 5; // 25mA @ 5V = 125mW (Arduino Uno example)
fl::u32 total_power = FastLED.getEstimatedPowerInMilliWatts() + mcu_power_mW;
Uses the configured power-scaling response. Default is linear scaling; use model.exponent via setPowerModel() or the setPowerScalingExponent() convenience wrapper to enable a non-linear model.
See also
setMaxPowerInMilliWatts()
setPowerModel()
setPowerScalingExponent()

Definition at line 415 of file FastLED.cpp.hpp.

415 {
416 fl::u32 total_power_mW = 0;
417
418 // Sum unscaled power from all LED controllers using visitor pattern
419 CLEDController::visitControllers([&total_power_mW](const CLEDController* /*controller*/, fl::span<const CRGB> leds) {
420 if (!leds.empty()) {
421 total_power_mW += calculate_unscaled_power_mW(leds);
422 }
423 });
424
425 // Determine effective brightness
426 fl::u8 effective_brightness = mScale;
427
428 if (apply_limiter && mPPowerFunc) {
429 // Power limiting is enabled and user wants limited power - calculate brightness after limiting
430 // This calls calculate_max_brightness_for_power_mW(mScale, mNPowerData)
431 effective_brightness = (*mPPowerFunc)(mScale, mNPowerData);
432 }
433
434 // Scale by the configured power-brightness response.
435 // Note: MCU power consumption is NOT included - caller should add platform-specific MCU power if needed
436 return scale_power_for_brightness(total_power_mW, effective_brightness);
437}
power_func mPPowerFunc
function for overriding brightness when using FastLED.show();
Definition FastLED.h:616
CRGB * leds()
Get a pointer to led data for the first controller.
fl::u8 mScale
the current global brightness scale setting
Definition FastLED.h:612
fl::u32 mNPowerData
max power use parameter
Definition FastLED.h:615
static void visitControllers(Visitor &&visitor) FL_NOEXCEPT
Visit all controllers in the linked list with a visitor The visitor must be a callable that accepts (...
fl::CLEDController CLEDController
fl::u32 scale_power_for_brightness(fl::u32 total_mW, fl::u8 brightness)
Applies the configured power-scaling response to a total power value.
fl::u32 calculate_unscaled_power_mW(fl::span< const CRGB > leds)
unsigned char u8
Definition stdint.h:131

References calculate_unscaled_power_mW(), leds(), mNPowerData, mPPowerFunc, mScale, scale_power_for_brightness(), and fl::CLEDController::visitControllers().

+ Here is the call graph for this function: