RGB.brightness doesn't seem to be working [SOLVED]

So I’ve been playing around with the RGB led built in to the core, and I can control the brightness using the individual red, green and blue values, but if I set the brightness with RGB.brightness, it’s really not working. The example code below results the RGB light being off until it hits the second loop, when it goes full on, and then as it continues, the light stays full on, without ever shutting off. I’m building with the web IDE to try to eliminate variables, but it didn’t seem to be working when building locally either. Any ideas anyone? Thanks!

void setup() {
    Serial.begin(9600);
    while (!Serial.available());
    RGB.control(true);
    RGB.color(0, 0, 0);
    RGB.brightness(0);
}

void loop() {
    RGB.color(255,255,255);
    Serial.println(0);
    RGB.brightness(0);
    delay(1000);
    RGB.brightness(63);
    Serial.println(63);
    delay(1000);
    RGB.brightness(127);
    Serial.println(127);
    delay(1000);
    RGB.brightness(191);
    Serial.println(191);
    delay(1000);
    Serial.println(255);
    RGB.brightness(255);
    delay(1000);
}

Just a random thought, but could you try setting the brightness, and then setting the color again?
The RGB value is set at the beginning, and it’s set to 255 brightness on the end, after which the color value is called again. Then changing brightness again doesn’t have an effect, and the last brightness level is again 255 before calling the color value again, thus you won’t notice any difference.

I think they had in mind that you would only use the brightness at startup, to manage the LED. So they expect a brightness level, to which they adjust new values.

Then again, this is just a random thought, so I could be mistaken. Doesn’t hurt to try though :slight_smile:

Good luck!

1 Like

These are good ideas. I checked the code to confirm and it does look like the intent is that changing brightness will recompute the rgb values.

the RGB.brightness() call calls LED_Brightness() in hw_config.c:

3 Likes

That seems like odd behavior. Grumble grumble. :slight_smile: But it works now! Thanks guys!

1 Like

I’m not sure I follow you @mublepins - it looks to me like the intended behaviour is what you were expecting. So the question really is - why doesn’t the code work as expected?

I flashed your code and verified that it doesn’t work as expected - I don’t see any change in brightness for the first iteration (LED off) and then it was at full brightness thereafter. I tried adding a RGB.control() to the loop() as well, but no change there.

1 Like

@mdma That’s a good question. With my little knowledge of the c code and the details of the microcontroller, it seems like it should work the way I had it. Until someone me, I made a library that takes care of control, and doesn’t care what order you set things in. It also uses a nonlinear lookup curve to adjust for the nonlinearity of visual perception.

1 Like

Awesome! Good catch on the non-linearity - that has bugged me too! :slight_smile: