# Any hints how I can make the power button make the led full brightness

**URL:** <https://forum.arduino.cc/t/any-hints-how-i-can-make-the-power-button-make-the-led-full-brightness/1428296>\
**Category:** General Guidance\
**Created:** [January 31, 2026, 3:30pm UTC](https://forum.arduino.cc/t/any-hints-how-i-can-make-the-power-button-make-the-led-full-brightness/1428296 "2026-01-31T15:30:22Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![roelofw](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/roelofw/32/1101110_2.png) [@roelofw](https://forum.arduino.cc/u/roelofw)\
**Post date:** [January 31, 2026, 3:30pm UTC](https://forum.arduino.cc/t/any-hints-how-i-can-make-the-power-button-make-the-led-full-brightness/1428296/1 "2026-01-31T15:30:22Z")

</div>

Hello,

IM finally at the last challenge of the McWorther course where I have to do this :

When you press the power button , the RGB led needs to be white full brightness  
When you press the undo button, the RGB led needs to be off.  
When you press the 1 button, the RGB led needs to be red

So far no problems.

but now it getting a little hard for me

When you press the `|<<` button the brightness must be less but when you press the power button , the white needs to be full bright  
and when I choose another button for another color, the brightness must stay the same.

Any hints how I can achieve this ?

Project so far : [https://wokwi.com/projects/454673983435304961](https://wokwi.com/projects/454673983435304961)

---

<div class="post-metadata">

**Author:** ![xfpd](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/xfpd/32/1120236_2.png) [@xfpd](https://forum.arduino.cc/u/xfpd)\
**Post date:** [January 31, 2026, 3:42pm UTC](https://forum.arduino.cc/t/any-hints-how-i-can-make-the-power-button-make-the-led-full-brightness/1428296/2 "2026-01-31T15:42:20Z")

</div>

I would guess all your answers are in the instructions (the person has been doing Arduino instruction for some years), so, include a link to the instructions.

---

<div class="post-metadata">

**Author:** ![J-M-L](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/j-m-l/32/766245_2.png) [@J-M-L](https://forum.arduino.cc/u/J-M-L)\
**Post date:** [January 31, 2026, 3:43pm UTC](https://forum.arduino.cc/t/any-hints-how-i-can-make-the-power-button-make-the-led-full-brightness/1428296/3 "2026-01-31T15:43:30Z")

</div>

add a 4th parameter which is the brightness on top of the R, G and B Values.

You then need a function that takes the theoretical R, G and B and the expected brightness and make some adjustment. A function like this could possibly work

```arduino
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;
}

```

The formula for brightness uses the weighted sum `0.299*R + 0.587*G + 0.114*B` because human vision is more sensitive to green light, less to red, and even less to blue

---

<div class="post-metadata">

**Author:** ![xfpd](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/xfpd/32/1120236_2.png) [@xfpd](https://forum.arduino.cc/u/xfpd)\
**Post date:** [January 31, 2026, 3:50pm UTC](https://forum.arduino.cc/t/any-hints-how-i-can-make-the-power-button-make-the-led-full-brightness/1428296/4 "2026-01-31T15:50:29Z")

</div>

> [@J-M-L](#):
>
> 0.299_R + 0.587_G + 0.114\*B

That is cool. 3:6:1... i was visually happy with 1:1:1 for increasing/decreasing "white"

---

<div class="post-metadata">

**Author:** ![J-M-L](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/j-m-l/32/766245_2.png) [@J-M-L](https://forum.arduino.cc/u/J-M-L)\
**Post date:** [January 31, 2026, 3:55pm UTC](https://forum.arduino.cc/t/any-hints-how-i-can-make-the-power-button-make-the-led-full-brightness/1428296/5 "2026-01-31T15:55:42Z")

</div>

> [@xfpd](#):
>
> That is cool. 3:6:1

The coefficients 0.299 for red, 0.587 for green, and 0.114 for blue come from the ITU-R BT.601 standard (quite old - formalized in 1982) where they defined the luminance component (Y) for standard-definition television.

They were derived from measurements of human visual sensitivity, specifically the photopic luminosity function, which quantifies how the human eye perceives brightness at different wavelengths.

---

<div class="post-metadata">

**Author:** ![roelofw](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/roelofw/32/1101110_2.png) [@roelofw](https://forum.arduino.cc/u/roelofw)\
**Post date:** [January 31, 2026, 4:14pm UTC](https://forum.arduino.cc/t/any-hints-how-i-can-make-the-power-button-make-the-led-full-brightness/1428296/6 "2026-01-31T16:14:36Z")

</div>

oke

So I can use then 255 for full brightness of the white and a lower number for the rest of the colors ?

---

<div class="post-metadata">

**Author:** ![J-M-L](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/j-m-l/32/766245_2.png) [@J-M-L](https://forum.arduino.cc/u/J-M-L)\
**Post date:** [January 31, 2026, 4:33pm UTC](https://forum.arduino.cc/t/any-hints-how-i-can-make-the-power-button-make-the-led-full-brightness/1428296/7 "2026-01-31T16:33:46Z")

</div>

You maintain R,G, B and Y (for the brightness) but when updating the led, you call the function to get the adjusted r, g, b

bringing back full brightness Y = 255  
lowering the brightness Y = (Y-1); (as Y is a uint8\_t it will circle back to 255 if you go below 0)  
increasing the brightness Y = (Y+1); (as Y is a uint8\_t it will circle back to 0 if you go above 255)

---

<div class="post-metadata">

**Author:** ![roelofw](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/roelofw/32/1101110_2.png) [@roelofw](https://forum.arduino.cc/u/roelofw)\
**Post date:** [January 31, 2026, 4:34pm UTC](https://forum.arduino.cc/t/any-hints-how-i-can-make-the-power-button-make-the-led-full-brightness/1428296/8 "2026-01-31T16:34:27Z")

</div>

oke,

So this is what you mean

```arduino
#include <IRremote.hpp>

const byte irReceivePin = 2;

const byte rPin = 9;
const byte gPin = 6;
const byte bPin = 5;

int 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 : 
        adjustedRgbForBrightness(255, 255, 255, brightness, outR, outG, outB);
        break; // POWER for full bright white
      case 0x3DC2FF00 :
         adjustedRgbForBrightness(0, 0, 0, 0, outR, outG, outB);
         break; // undo for all lights off
      case 0xCF30FF00 :
           adjustedRgbForBrightness(255, 0, 0, brightness, outR, outG, outB);
         break; // 1 button for red
      case 0X1FE0FF00:
        if (brightness > 0) {
          brightness--; 
        }
        break; 
      default: break;
    }
    
    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();
}

```

---

<div class="post-metadata">

**Author:** ![J-M-L](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/j-m-l/32/766245_2.png) [@J-M-L](https://forum.arduino.cc/u/J-M-L)\
**Post date:** [January 31, 2026, 4:42pm UTC](https://forum.arduino.cc/t/any-hints-how-i-can-make-the-power-button-make-the-led-full-brightness/1428296/9 "2026-01-31T16:42:34Z")

</div>

if 0x5DA2FF00 is POWER, we usually put the comment there, not after the break

```arduino
      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

```arduino
      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

```arduino
#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)

---

<div class="post-metadata">

**Author:** ![roelofw](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/roelofw/32/1101110_2.png) [@roelofw](https://forum.arduino.cc/u/roelofw)\
**Post date:** [January 31, 2026, 4:46pm UTC](https://forum.arduino.cc/t/any-hints-how-i-can-make-the-power-button-make-the-led-full-brightness/1428296/10 "2026-01-31T16:46:20Z")

</div>

oke

but it is then not , that if I change the brightness it also changes for the white.  
That is not the challenge as I understand it.

As far as I understand the brightness needs to change for all colors except when you press the power button. then it always needs to be full bright.

When you change to another color, which I have to implement, then the "last" brightness needs to be used.

---

<div class="post-metadata">

**Author:** ![roelofw](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/roelofw/32/1101110_2.png) [@roelofw](https://forum.arduino.cc/u/roelofw)\
**Post date:** [January 31, 2026, 4:55pm UTC](https://forum.arduino.cc/t/any-hints-how-i-can-make-the-power-button-make-the-led-full-brightness/1428296/11 "2026-01-31T16:55:34Z")

</div>

and if i want to increase the brightness do I need a check that the brightness cannot be above 255?

---

<div class="post-metadata">

**Author:** ![J-M-L](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/j-m-l/32/766245_2.png) [@J-M-L](https://forum.arduino.cc/u/J-M-L)\
**Post date:** [January 31, 2026, 5:02pm UTC](https://forum.arduino.cc/t/any-hints-how-i-can-make-the-power-button-make-the-led-full-brightness/1428296/12 "2026-01-31T17:02:41Z")

</div>

> [@roelofw](#):
>
> When you change to another color, which I have to implement, then the "last" brightness needs to be used.

when I do this for red, I don't touch the brightness variable, so whatever it its, it stays.

> [@J-M-L](#):
>
> ```arduino
> case 0xCF30FF00 :// 1 for red, (don't change brightness ?)
> r = 255; g = 0; b = 0;
> break;
> 
> ```

but when I do

> [@J-M-L](#):
>
> ```arduino
> case 0x5DA2FF00 : // POWER for full bright white
> r = 255; g = 255; b = 255; brightness = 255;
> break;
> 
> ```

then I go full white and full brightness.

➜ do you mean that going full white should be full white but then not influence the existing brightness for the others ?

> [@roelofw](#):
>
> if i want to increase the brightness do I need a check that the brightness cannot be above 255

I changed the type to byte, so it's always going to be between 0 and 255 and if you do 255+1 it goes back automatically to 0.

---

<div class="post-metadata">

**Author:** ![roelofw](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/roelofw/32/1101110_2.png) [@roelofw](https://forum.arduino.cc/u/roelofw)\
**Post date:** [January 31, 2026, 5:05pm UTC](https://forum.arduino.cc/t/any-hints-how-i-can-make-the-power-button-make-the-led-full-brightness/1428296/13 "2026-01-31T17:05:45Z")

</div>

oke,

Then I think I can implement the decrease function and the other 5 colors

---

<div class="post-metadata">

**Author:** ![J-M-L](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/j-m-l/32/766245_2.png) [@J-M-L](https://forum.arduino.cc/u/J-M-L)\
**Post date:** [January 31, 2026, 5:10pm UTC](https://forum.arduino.cc/t/any-hints-how-i-can-make-the-power-button-make-the-led-full-brightness/1428296/14 "2026-01-31T17:10:37Z")

</div>

yeah, just do it and see if it works to your liking

---

<div class="post-metadata">

**Author:** ![roelofw](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/roelofw/32/1101110_2.png) [@roelofw](https://forum.arduino.cc/u/roelofw)\
**Post date:** [January 31, 2026, 5:20pm UTC](https://forum.arduino.cc/t/any-hints-how-i-can-make-the-power-button-make-the-led-full-brightness/1428296/15 "2026-01-31T17:20:11Z")

</div>

Done :

> **[RGB and IR remote - Wokwi ESP32, STM32, Arduino Simulator](https://wokwi.com/projects/454673983435304961)**
>
> Run IoT and embedded projects in your browser: ESP32, STM32, Arduino, Pi Pico, and more. No installation required!

the only thing I would change is that if you change color it fades to the next color.  
But that is pure looks.

I hope I did a good job and ready for some more difficult challenges.

---

<div class="post-metadata">

**Author:** ![J-M-L](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/j-m-l/32/766245_2.png) [@J-M-L](https://forum.arduino.cc/u/J-M-L)\
**Post date:** [January 31, 2026, 5:24pm UTC](https://forum.arduino.cc/t/any-hints-how-i-can-make-the-power-button-make-the-led-full-brightness/1428296/16 "2026-01-31T17:24:42Z")

</div>

> [@roelofw](#):
>
> the only thing I would change

give it a try

---

<div class="post-metadata">

**Author:** ![roelofw](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/roelofw/32/1101110_2.png) [@roelofw](https://forum.arduino.cc/u/roelofw)\
**Post date:** [January 31, 2026, 5:27pm UTC](https://forum.arduino.cc/t/any-hints-how-i-can-make-the-power-button-make-the-led-full-brightness/1428296/17 "2026-01-31T17:27:30Z")

</div>

oke

First some googling to see how to approach this.

---

<div class="post-metadata">

**Author:** ![J-M-L](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/j-m-l/32/766245_2.png) [@J-M-L](https://forum.arduino.cc/u/J-M-L)\
**Post date:** [January 31, 2026, 5:32pm UTC](https://forum.arduino.cc/t/any-hints-how-i-can-make-the-power-button-make-the-led-full-brightness/1428296/18 "2026-01-31T17:32:19Z")

</div>

I think the easies way would be to use an Hue Saturation Brightness model (HSB) rather than RGB.

Only convert the HSB value to RGB at the very end when you want to address the LED's pins.

this way ramping Brightness is straight, and going from one Hue to the next is also a simple interpolation over time.

there are also an infinite number of path to go from one color to another - you'll have to decide on that too.

 ![image](https://europe1.discourse-cdn.com/arduino/original/4X/c/3/b/c3b75f4fcc792dc4a1114885c70c6fd2565a99e3.jpeg)

---

<div class="post-metadata">

**Author:** ![roelofw](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/roelofw/32/1101110_2.png) [@roelofw](https://forum.arduino.cc/u/roelofw)\
**Post date:** [January 31, 2026, 5:34pm UTC](https://forum.arduino.cc/t/any-hints-how-i-can-make-the-power-button-make-the-led-full-brightness/1428296/19 "2026-01-31T17:34:55Z")

</div>

oke

Then I have to find out what the HSB values of the colors are.  
and how I can use them in the output

---

<div class="post-metadata">

**Author:** ![J-M-L](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/j-m-l/32/766245_2.png) [@J-M-L](https://forum.arduino.cc/u/J-M-L)\
**Post date:** [January 31, 2026, 5:40pm UTC](https://forum.arduino.cc/t/any-hints-how-i-can-make-the-power-button-make-the-led-full-brightness/1428296/20 "2026-01-31T17:40:49Z")

</div>

yes. study a bit the color models and what they offer.

> **[Color model](https://en.wikipedia.org/wiki/Color_model)**
>
> In color science, a color model is an abstract mathematical model describing the way colors can be represented as tuples of numbers, typically as three or four values or color components. It differs from a color space in that a color model is not absolute, that is, there is no way to map a color within a color model to a point in a color space.
> This article describes ways in which human color vision can be modeled, and discusses some of the models in common use.
> One can picture this space as...

[Next page](https://forum.arduino.cc/t/any-hints-how-i-can-make-the-power-button-make-the-led-full-brightness/1428296.md?page=2)
