Situation: Creating matrix effects based on leds[i] += …
Problem: By adding a color the result gets brighter and brighter until white.
Solution: Scaling down leds[i] before/after adding with leds[i].nscale8
Question: How to do that scaling dynamically depending on the actual content of the screenbuffer to avoid a blackout / whiteout?
I’m looking for a kind of color/brightness compressor with AUTOthreshold, ratio, attack and release.
Any hint, link or remark how that could be abstracted is appreciated!
That turned out to be more difficult than I expected. Well, this function for dynamic scaling will do the job for now:
/*
#define MAX 195840
(in my case 16 x 16 LEDs * 3 colors * 255 maxvalue = 195840)
unsigned long counter;
*/
void AutoDim()
{
// calculate average brightness of the screen
counter = 0;
for(int i = 0; i < NUM_LEDS; i++) {
counter += leds[i].r;
counter += leds[i].g;
counter += leds[i].b;
}
// 0 means all off, 255 means all white
byte bright = (counter * 255) / MAX;
// scale down depending on actual brightness
for(int i = 0; i < NUM_LEDS; i++) {
leds[i].nscale8(255 - bright);
}
}