FastLED 3.9.15
Loading...
Searching...
No Matches
auto_brightness.cpp
Go to the documentation of this file.
1// auto_brightness.cpp
2#include "auto_brightness.h"
3
4float getAverageBrightness(CRGB *leds, int numLeds) {
5 uint32_t total = 0;
6 for (int i = 0; i < numLeds; i++) {
7 total += leds[i].r + leds[i].g + leds[i].b;
8 }
9 float avgValue = float(total) / float(numLeds * 3);
10 return (avgValue / 255.0f) * 100.0f;
11}
12
13uint8_t applyBrightnessCompression(float inputBrightnessPercent,
14 uint8_t maxBrightness, float lowThreshold,
15 float highThreshold) {
16 float maxBrightnessPercent = (maxBrightness / 255.0f) * 100.0f;
17 if (inputBrightnessPercent < lowThreshold) {
18 return 255;
19 } else if (inputBrightnessPercent < highThreshold) {
20 float range = highThreshold - lowThreshold;
21 float progress = (inputBrightnessPercent - lowThreshold) / range;
22 float targetPercent =
23 100.0f - (progress * (100.0f - maxBrightnessPercent));
24 return static_cast<uint8_t>((targetPercent / 100.0f) * 255.0f);
25 } else {
26 return maxBrightness;
27 }
28}
fl::CRGB leds[NUM_LEDS]
uint8_t applyBrightnessCompression(float inputBrightnessPercent, uint8_t maxBrightness, float lowThreshold, float highThreshold)
float getAverageBrightness(CRGB *leds, int numLeds)
fl::CRGB CRGB
Definition crgb.h:25