5#define FASTLED_INTERNAL
30static const uint8_t gRed_mW = 16 * 5;
31static const uint8_t gGreen_mW = 11 * 5;
32static const uint8_t gBlue_mW = 15 * 5;
33static const uint8_t gDark_mW = 1 * 5;
51#define POWER_DEBUG_PRINT 0
55static const uint8_t gMCU_mW = 25 * 5;
57static uint8_t gMaxPowerIndicatorLEDPinNumber = 0;
62 uint32_t red32 = 0, green32 = 0, blue32 = 0;
63 const CRGB* firstled = &(ledbuffer[0]);
64 uint8_t* p = (uint8_t*)(firstled);
66 uint16_t count = numLeds;
84 uint32_t total = red32 + green32 + blue32 + (gDark_mW * numLeds);
97 uint32_t requested_power_mW = ((uint32_t)total_mW * target_brightness) / 256;
99 uint8_t recommended_brightness = target_brightness;
100 if(requested_power_mW > max_power_mW) {
101 recommended_brightness = (uint32_t)((uint8_t)(target_brightness) * (uint32_t)(max_power_mW)) / ((uint32_t)(requested_power_mW));
104 return recommended_brightness;
112 uint32_t total_mW = gMCU_mW;
120#if POWER_DEBUG_PRINT == 1
121 Serial.print(
"power demand at full brightness mW = ");
122 Serial.println( total_mW);
125 uint32_t requested_power_mW = ((uint32_t)total_mW * target_brightness) / 256;
126#if POWER_DEBUG_PRINT == 1
127 if( target_brightness != 255 ) {
128 Serial.print(
"power demand at scaled brightness mW = ");
129 Serial.println( requested_power_mW);
131 Serial.print(
"power limit mW = ");
132 Serial.println( max_power_mW);
135 if( requested_power_mW < max_power_mW) {
137 if( gMaxPowerIndicatorLEDPinNumber ) {
138 Pin(gMaxPowerIndicatorLEDPinNumber).
lo();
141#if POWER_DEBUG_PRINT == 1
142 Serial.print(
"demand is under the limit");
144 return target_brightness;
147 uint8_t recommended_brightness = (uint32_t)((uint8_t)(target_brightness) * (uint32_t)(max_power_mW)) / ((uint32_t)(requested_power_mW));
148#if POWER_DEBUG_PRINT == 1
149 Serial.print(
"recommended brightness # = ");
150 Serial.println( recommended_brightness);
152 uint32_t resultant_power_mW = (total_mW * recommended_brightness) / 256;
153 Serial.print(
"resultant power demand mW = ");
154 Serial.println( resultant_power_mW);
160 if( gMaxPowerIndicatorLEDPinNumber ) {
161 Pin(gMaxPowerIndicatorLEDPinNumber).
hi();
165 return recommended_brightness;
171 gMaxPowerIndicatorLEDPinNumber = pinNumber;
CFastLED FastLED
Global LED strip management instance.
central include file for FastLED, defines the CFastLED class/object
void delay(unsigned long ms)
Delay for the given number of milliseconds.
void show(uint8_t scale)
Update all our controllers with the current led colors, using the passed in brightness.
void setMaxPowerInVoltsAndMilliamps(uint8_t volts, uint32_t milliamps)
Set the maximum power to be used, given in volts and milliamps.
void setMaxPowerInMilliWatts(uint32_t milliwatts)
Set the maximum power to be used, given in milliwatts.
Base definition for an LED controller.
CLEDController * next()
Get the next controller in the linked list after this one.
virtual int size()
How many LEDs does this controller manage?
static CLEDController * head()
Get the first LED controller in the linked list of controllers.
CRGB * leds()
Pointer to the CRGB array for this controller.
Naive fallback solution for low level pin access.
void hi()
Set the pin state to HIGH
void lo()
Set the pin state to LOW
void set_max_power_in_milliwatts(uint32_t powerInmW)
Set the maximum power used in watts.
void show_at_max_brightness_for_power()
Similar to CFastLED::show(), but pre-adjusts brightness to keep below the power threshold.
void delay_at_max_brightness_for_power(uint16_t ms)
Similar to CFastLED::delay(), but pre-adjusts brightness to keep below the power threshold.
uint32_t calculate_unscaled_power_mW(const CRGB *ledbuffer, uint16_t numLeds)
Determines how many milliwatts the current LED data would draw at max brightness (255)
void set_max_power_in_volts_and_milliamps(uint8_t volts, uint32_t milliamps)
Set the maximum power used in milliamps for a given voltage.
void set_max_power_indicator_LED(uint8_t pinNumber)
Select a pin with an LED that will be flashed to indicate that power management is pulling down the b...
uint8_t calculate_max_brightness_for_power_vmA(const CRGB *ledbuffer, uint16_t numLeds, uint8_t target_brightness, uint32_t max_power_V, uint32_t max_power_mA)
Determines the highest brightness level you can use and still stay under the specified power budget f...
uint8_t calculate_max_brightness_for_power_mW(const CRGB *ledbuffer, uint16_t numLeds, uint8_t target_brightness, uint32_t max_power_mW)
Determines the highest brightness level you can use and still stay under the specified power budget f...
Functions to limit the power used by FastLED.
Representation of an RGB pixel (Red, Green, Blue)