About rgb main dimmer controlling

hello all, is there any way to control brightness of all three rgb leds at same time ? for example if i have mode with any random color like this ,

mode == 0
analogWrite(greenled, 150);
analogWrite(redled, 75);
analogWrite(blueled, 100);

so how can i dim or bright this same color scheme ? or do i have to control this whole mode for dim or brigth ? sorry for my noob question

Things will not happen at the same time.

But things can happen in a sequence that takes microseconds. No one will notice that...
...so it seems to happen at the same time.

Do you want to dim the example color till it is black?
And then again brighten it?

Or do I misunderstand?

1 Like

If you mean, "how can I vary the brightness of a colour hue?", the answer is, there is no easy mathematical formula, because of the complexity of human colour perception. Look up "CIE chromaticity diagram" and "display gamma". A "hue" or colour shade, depends on a balance of perceived intensities, which do not correspond to simple scalar RGB intensities, as produced by the PWM modulation of the LEDs in the RGB driver IC.

Sorry if the fact disappoints you.

1 Like

If OP accepts that the color will slightly change upon dimming, I would say dimming should not be a problem ...

I understood, "this same colour scheme" to mean constant hue. But the OP needs to clarify...

yes. you got me bud.


uint16_t red =140;
uint16_t blue=230:
uint16_t dimmedRed, dimmedBlue;

for (int i = 256; i>0; i--){
    dimmedRed = i*red/256;
    dimmedBlue = i*blue/256;
}

This should get you started...
(Add green yourself...)

1 Like
int percentBrightness = 83;
analogWrite(greenled, 150 * percentBrightness / 100);
analogWrite(redled, 75 * percentBrightness / 100);
analogWrite(blueled, 100 * percentBrightness / 100);
1 Like

that,s awesome mate. many thanks for your cooperate. really appreciated.

and also thanks for your reply mate. i found this site very helpful for beginner like me. thanks again to you and build_1971.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.