Hi, could someone recommend a good brightness scaling function or method?

gplus
(Will Waterston) #1

Hi,

could someone recommend a good brightness scaling function or method? I’ve seen so many like nscale and multimap, but I’m wondering if there is a commonly accepted method, something thats fast?

I’m currently just using pow(2,i), ie each brightness level is double the next lowest, but I suspect there is a better method.

I want to have a fixed length array that goes from 1 to the maximum brightness (which can be variable) with good brightness scaling (ie logarithmic or geometric) in between.

Thanks.

(Marc Miller) #2

So the fixed length array always starts at 1 and has a ramp up of pre-calculated values up to a maximum brightness value?

(Marc Miller) #3

Doesn’t specifically answer your question, but was interesting info.

Are you going to use a lookup table, or were you wanting to calculate the curve values in real time?

I was messing with this a bit and tried this out:

for (uint8_t i=0; i < NUM_LEDS; i++) {
brightness = (1- (log(i+1)/log(steps))) * maxBrightness;
fill_solid(leds, NUM_LEDS, CHSV(0,255,brightness));
FastLED.show();
Serial.println(brightness);
delay(30);
}

(steps = how many steps you want to go from 0 to 255)

(Will Waterston) #4

@marmil yes thats correct. I’m just trying to get a graduated scale from dark to light thats approximately linear in brightness (as opposed to linear in value)

(Will Waterston) #5

@marmil I’ll try that thanks, I would prefer a lookup table. My code is small so I can sacrifice a bit of memory for speed.