if 0x5DA2FF00 is POWER, we usually put the comment there, not after the break
case 0x5DA2FF00 : // POWER means full bright white
adjustedRgbForBrightness(255, 255, 255, brightness, outR, outG, outB);
break;
and in that case if it's full bright then you need to change brightness
case 0x5DA2FF00 : // POWER means full bright white
brightness = 255;
adjustedRgbForBrightness(255, 255, 255, brightness, outR, outG, outB);
break;
also I would keep track of the original r, g, b so more something like
#include <IRremote.hpp>
const byte irReceivePin = 2;
const byte rPin = 9;
const byte gPin = 6;
const byte bPin = 5;
byte brightness = 255;
byte r, g, b;
byte outR, outG, outB;
void adjustedRgbForBrightness(uint8_t r, uint8_t g, uint8_t b, uint8_t targetBrightness,
uint8_t &outR, uint8_t &outG, uint8_t &outB)
{
float currentBrightness = 0.299f * r + 0.587f * g + 0.114f * b;
if (currentBrightness == 0) {
outR = outG = outB = 0;
return;
}
float scale = targetBrightness / currentBrightness;
int tempR = r * scale;
int tempG = g * scale;
int tempB = b * scale;
outR = tempR > 255 ? 255 : tempR;
outG = tempG > 255 ? 255 : tempG;
outB = tempB > 255 ? 255 : tempB;
}
void handleCommand() {
if (IrReceiver.decode()) {
switch (IrReceiver.decodedIRData.decodedRawData) {
case 0x5DA2FF00 : // POWER for full bright white
r = 255; g = 255; b = 255; brightness = 255;
break;
case 0x3DC2FF00 : // undo for all lights off
r = 0; g = 0; b = 0; brightness = 0;
break;
case 0xCF30FF00 :// 1 for red, (don't change brightness ?)
r = 255; g = 0; b = 0;
break;
case 0X1FE0FF00: // a comment is needed here
brightness--;
break;
default: break;
}
adjustedRgbForBrightness(r, g, b, brightness, outR, outG, outB);
analogWrite(rPin, outR);
analogWrite(gPin, outG);
analogWrite(bPin, outB);
IrReceiver.resume();
}
}
void setup() {
pinMode(rPin, OUTPUT);
pinMode(gPin, OUTPUT);
pinMode(bPin, OUTPUT);
Serial.begin(115200);
IrReceiver.begin(irReceivePin);
Serial.println(F("Ready"));
}
void loop() {
handleCommand();
}
(typed here)