# White Balance/Color Temp

Thanks, that’s interesting.
It’s strange to me that the chips on the LED’s themselves are controlling things… But I know that’s how it is now… (I’m coming back to electronics after about 20 years… I was an EE in my youth… Somehow started an IT business and the EE became a hobby… then I got busy w/ kids and life, and EE became non existent)

I hear your brother I got kids to. Not much free

Twilight

Hello,
I’m back to being bothered by the white balance of my LED’s… and am apparently bumping both threads I started about it… (Actually, I’ll erase the other one…).
Basically, the code zranger1 posted a few years ago has been great. But, my LED’s are quite a bit more blue at lower outputs and while that didn’t bother me a couple years ago, it does now… Has anyone fixed anything like that?
Using just white, if I fade from full brightness to completely dim, it gets more and more blue as it goes dim. It seems like maybe I could tell it to increase red, or decrease blue and green, relative to that pixels “v” value, I guess? But I don’t know where to start for that.
If anyone’s done that, could you post the code?
Thank you.

To keep 0 at 0, 1 at 1, and lower the level in between, try squaring blue. Maybe that will be a bit too much, so you could make a slider to interpolate between blue and blue^2.

``````var Mix = 0
export function sliderMix(v) {
Mix = v
}

render (index) {
// ... calculate r g b
rgb(r, g, b * (1-Mix) + (b*b) * Mix)
}
``````

Then once you know the best value for `Mix`, you can hardcode it!

``````render (index) {
// ... calculate r g b
rgb(r, g, b * (1-0.75731) + (b*b) * 0.75731)
}
``````
2 Likes

I suppose you could also interpolate the power via `pow(b, Mix+1)` or even go towards b^3 with `pow(b, (Mix*2)+1)`

I haven’t had a lot of time to play with these yet… But I quickly added it to one of the basic demonstration patterns which fades white in random ways. (I think it was the “Time and Animation” pattern.
And it works mostly, but at times goes full blue/green. I am guessing when it goes to zero, they actually go fully on.
I need to mess with it some more, but the lights are in my sons room… And he’s in bed now :(.

Thanks for the help!

The technique only makes sense when the input number is between 0 and 1. The PB output always clamps the value, so many patterns are lazy, returning numbers less than 0 or more than 1.

In this case, `pow(negative number, some fraction)` might come out positive which would explain why it’s going bright on at that end. So, you should clamp it yourself before the transformation … and maybe try different values for g and b since I doubt their output curves are exactly the same:

`rgb(r, pow(clamp(g,0,1), gmix+1), pow(clamp(b,0,1), bmix+1))`

Thanks a lot!
I think after a few more questions I’ll finally understand it enough, for the manual to start making sense :). (I work in IT, but am not a programmer).
I do understand what’s going on… I just can’t think of what to do on my own yet.

1 Like

I’m a programmer and I am always up to my neck in understanding what’s going on but not being able to think of what to do yet, but I can do a little bit more every day!