# 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:** 2

<div class="post-metadata">

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

</div>

> [@roelofw](#):
>
> Any hints how I can achieve this ?

Does McWhorther publish his solutions?

I'd like to see what he expects _you_ to be able to do at this point, I'm betting it is done in a very simple manner.

_Later._

McWhorther seems to use neither _switch_/_case_, the ternary operator nor functions at this point.

He does not publish, or TBC I could not find solutions to homework problems. But looking ahead to the ultimate sketch he expects you will arrive at, we see indeed he continues in his straight code all in the loop style. Appropriate for where he's led you.

He uses a global variable

```arduino
float dFact = 1; // dimming factor

```

And using the way he links any IR button to an action, handles dimming (and undimming) by tweaking and constraining the brightness factor, viz:

```arduino
  if (myCom == "dn") {
    dFact = dFact * 0.75; // dim
  }

  if (myCom == "up") {
    dFact = dFact * 1.30; // brighten
     if (dFact > 1) {
      dFact = 1; //... fix overflow
     }
  } 

```

I expect you could fit that into your _switch_ statement.

Later, at the point of writing the values, the brightness factor is applied:

```arduino
  analogWrite(rPin, rBright * dFact);
  analogWrite(gPin, gBright * dFact);
  analogWrite(bPin, bBright * dFact);

```

I guess he isn't terribly worried about the physiology of human vision WRT PWM modulated RGB LEDs.

Everyone learns differently: I think it is useful to see things done literally as is McW's habit, and perhaps suffer a bit while writing code that way.

At the very least it makes the actual necessary steps of the algorithm the issue, rather than any fancy languages features you dress them up in.

a7

---

<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, 6:00pm UTC](https://forum.arduino.cc/t/any-hints-how-i-can-make-the-power-button-make-the-led-full-brightness/1428296/22 "2026-01-31T18:00:14Z")

</div>

THat is correct

HE never used a switch statement but a lot of if then's .  
I do not like it and have learned some more c++ with [exercism.io](http://exercism.io) solutions.

you find my solution complex ??

---

<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, 6:02pm UTC](https://forum.arduino.cc/t/any-hints-how-i-can-make-the-power-button-make-the-led-full-brightness/1428296/23 "2026-01-31T18:02:18Z")

</div>

> [@roelofw](#):
>
> you find my solution complex ??

So far it’s very readable

---

<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, 6:06pm UTC](https://forum.arduino.cc/t/any-hints-how-i-can-make-the-power-button-make-the-led-full-brightness/1428296/24 "2026-01-31T18:06:11Z")

</div>

oke

I get the feeling that Alto777 finds my solution complex

Still looking how I can decrease or increase the brightness and how I can convert to RGB what the arduino seems to need

---

<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, 6:21pm UTC](https://forum.arduino.cc/t/any-hints-how-i-can-make-the-power-button-make-the-led-full-brightness/1428296/25 "2026-01-31T18:21:41Z")

</div>

IM still confused

So red will be 0, 100, 50

But how do I now increase or decrease the brightness ?

oke, looks like I have to increase the last number between 50 and 100

---

<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, 6:45pm UTC](https://forum.arduino.cc/t/any-hints-how-i-can-make-the-power-button-make-the-led-full-brightness/1428296/26 "2026-01-31T18:45:17Z")

</div>

> [@roelofw](#):
>
> oke, looks like I have to increase the last number between 50 and 100

Yes the last value will drive brightness. Not sure why you say only from 50 though.

---

<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, 6:45pm UTC](https://forum.arduino.cc/t/any-hints-how-i-can-make-the-power-button-make-the-led-full-brightness/1428296/27 "2026-01-31T18:45:34Z")

</div>

> [@roelofw](#):
>
> red will be 0, 100, 50

~~Only if you are using GRB... and it will be closer to purple (or if using BRG, orange)~~  
See post 28 for HSV...

> [@roelofw](#):
>
> how do I now increase

Increase the color variables.

~~ 

```arduino
0+1, 100+1, 50+1

```

 ~~ I have a running Neopixel only using RGB values, and it gives my eyes all 16 million combinations, smoothly. I will dig-up the code.

---

<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, 6:46pm UTC](https://forum.arduino.cc/t/any-hints-how-i-can-make-the-power-button-make-the-led-full-brightness/1428296/28 "2026-01-31T18:46:12Z")

</div>

> [@xfpd](#):
>
> Only if you are using GRB

He was taking HSB color space

| Color | H | S | B |
| --- | --- | --- | --- |
| Red | 0 | 100 | 100 |
| Orange | 30 | 100 | 100 |
| Yellow | 60 | 100 | 100 |
| Green | 120 | 100 | 100 |
| Cyan | 180 | 100 | 100 |
| Blue | 240 | 100 | 100 |
| Indigo | 275 | 100 | 100 |
| Violet | 300 | 100 | 100 |
| Magenta | 330 | 100 | 100 |
| White | 0 | 0 | 100 |
| Black | 0 | 0 | 0 |
| Gray | 0 | 0 | 50 |
| Pink | 350 | 50 | 100 |
| Brown | 30 | 100 | 60 |

In HSB the H (hue) value represents the color’s position on the color wheel from 0 to 360 degrees, S (saturation) is how pure the color is from 0 to 100%, and B (value/brightness) is how bright the color is from 0 to 100%.

 ![image](https://europe1.discourse-cdn.com/arduino/original/4X/2/9/0/2907ce68aa42f2a999bb3528147b089d59f78f80.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, 7:49pm UTC](https://forum.arduino.cc/t/any-hints-how-i-can-make-the-power-button-make-the-led-full-brightness/1428296/29 "2026-01-31T19:49:27Z")

</div>

> [@J-M-L](#):
>
> 60 100 100

@J-M-L im so far right now

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

but still confused how I can make that the power button the brightness stays always the same so at 100

---

<div class="post-metadata">

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

</div>

> [@roelofw](#):
>
> I get the feeling that Alto777 finds my solution complex

I did not find your solution complex.

a7

---

<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, 11:35pm UTC](https://forum.arduino.cc/t/any-hints-how-i-can-make-the-power-button-make-the-led-full-brightness/1428296/31 "2026-01-31T23:35:49Z")

</div>

What is this simulation in Post #29 to do? I pressed Power, FF, RW, play, return, test and 1 - 9 without any effect.

---

<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:** [February 1, 2026, 9:03am UTC](https://forum.arduino.cc/t/any-hints-how-i-can-make-the-power-button-make-the-led-full-brightness/1428296/32 "2026-02-01T09:03:19Z")

</div>

That is correct.

Post #29 is a attempt where work on to make things work with hsl colors.

I still have to figure out how I can convert hsl colors to rgb and how to make a fade between color1 and color2.

Working version with rgb you can find it in post #16  
and on this url : [https://wokwi.com/projects/454673983435304961](https://wokwi.com/projects/454673983435304961)

so if anybody have hints how to convert the hsl colors to rgb or make the fade im happy to listen.

---

<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:** [February 1, 2026, 9:10am UTC](https://forum.arduino.cc/t/any-hints-how-i-can-make-the-power-button-make-the-led-full-brightness/1428296/33 "2026-02-01T09:10:27Z")

</div>

> [@roelofw](#):
>
> I still have to figure out how I can convert hsl colors to rgb

it's a classical function - say you have Hue in 0–360 and Saturation and Value are 0–100 and you want to return RGB 0–255:

```arduino

struct RGB {
  uint8_t r;
  uint8_t g;
  uint8_t b;
};

RGB hsvToRgb(float h, float s, float v) {
  s /= 100.0f;
  v /= 100.0f;

  float r = 0, g = 0, b = 0;

  if (s == 0) {
    r = g = b = v;
  } else {
    h = fmod(h, 360.0f);
    if (h < 0) h += 360.0f;
    float hf = h / 60.0f;
    int i = (int)floor(hf);
    float f = hf - i;
    float p = v * (1.0f - s);
    float q = v * (1.0f - s * f);
    float t = v * (1.0f - s * (1.0f - f));

    switch (i) {
      case 0: r = v; g = t; b = p; break;
      case 1: r = q; g = v; b = p; break;
      case 2: r = p; g = v; b = t; break;
      case 3: r = p; g = q; b = v; break;
      case 4: r = t; g = p; b = v; break;
      case 5: default: r = v; g = p; b = q; break;
    }
  }

  RGB color;
  color.r = (uint8_t)round(r * 255.0f);
  color.g = (uint8_t)round(g * 255.0f);
  color.b = (uint8_t)round(b * 255.0f);
  return color;
}

```

---

<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:** [February 1, 2026, 9:23am UTC](https://forum.arduino.cc/t/any-hints-how-i-can-make-the-power-button-make-the-led-full-brightness/1428296/34 "2026-02-01T09:23:15Z")

</div>

thanks

oke,

That works as far as I can tell.

Next the fading from one color to another if you choose another color

---

<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:** [February 1, 2026, 9:41am UTC](https://forum.arduino.cc/t/any-hints-how-i-can-make-the-power-button-make-the-led-full-brightness/1428296/35 "2026-02-01T09:41:09Z")

</div>

> [@roelofw](#):
>
> Next the fading from one color to another if you choose another color

in the HSB model you can decide of a fixed path which is "going around" the color wheel by incrementing or decrementing H (of course stay within 0-360 as you cross boundaries)

 ![image](https://europe1.discourse-cdn.com/arduino/original/4X/9/0/1/9012786c3c6ded460c3d3b47c676ee1db2d4f13b.jpeg)

you don't touch S and B as you go around the wheel.

---

<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:** [February 1, 2026, 9:49am UTC](https://forum.arduino.cc/t/any-hints-how-i-can-make-the-power-button-make-the-led-full-brightness/1428296/36 "2026-02-01T09:49:59Z")

</div>

oke

And I think it would be nice that always the shortest path is chosen.  
Still some thinking to do.

---

<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:** [February 1, 2026, 9:53am UTC](https://forum.arduino.cc/t/any-hints-how-i-can-make-the-power-button-make-the-led-full-brightness/1428296/37 "2026-02-01T09:53:48Z")

</div>

> [@roelofw](#):
>
> always the shortest path is chosen

You can compute the shortest direction by normalizing the difference.

```cpp
int shortestHueStep(float startH, float endH) {
  float diff = endH - startH;

  if (diff > 180.0f) diff -= 360.0;
  else if (diff < -180.0f) diff += 360.0;

  return (diff > 0) ? 1 : (diff < 0) ? -1 : 0;
}

```

It works by checking if the raw difference is outside the ±180° range and adjusting accordingly. The return value is 1 for clockwise, -1 for counterclockwise, and 0 if the hues are equal so you can use that value as the increment (make sure you stay in the 0-360° limits) for each step you take.

---

<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:** [February 1, 2026, 2:17pm UTC](https://forum.arduino.cc/t/any-hints-how-i-can-make-the-power-button-make-the-led-full-brightness/1428296/38 "2026-02-01T14:17:00Z")

</div>

> [@roelofw](#):
>
> some thinking

I find printing formatted values help me "see/quantify" the patterns I programmed versus the patterns I want. [edit]In this sim... `trim()` demonstrates the numbers, `fade()` demonstrates timing.

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

---

<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:** [February 1, 2026, 7:34pm UTC](https://forum.arduino.cc/t/any-hints-how-i-can-make-the-power-button-make-the-led-full-brightness/1428296/39 "2026-02-01T19:34:21Z")

</div>

@J-M-L

I have a bug somewhere with the fade efffect.  
Or I get a fade color or no color at all.

Hopefully I can find it tomorrow or do I have a idea where I went wrong

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

---

<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:** [February 2, 2026, 12:33am UTC](https://forum.arduino.cc/t/any-hints-how-i-can-make-the-power-button-make-the-led-full-brightness/1428296/40 "2026-02-02T00:33:57Z")

</div>

> [@roelofw](#):
>
> a bug somewhere with the fade

You should print the raw numbers you are using and changing. Your "fade" works, but slowly, and "by 1s". Use the PWR, \<\<, \>\>, 1, 2, and 3 and watch your serial monitor.

> **same code with numbers**
>
> ```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 h, s, l;
> 
> struct RGB {
> uint8_t r;
> uint8_t g;
> uint8_t b;
> };
> 
> float currentH = 0, currentS = 0, currentL = 0;
> float targetH = 0, targetS = 0, targetL = 0;
> 
> const int fadeSteps = 100; // smoothness
> const int fadeDelay = 10; // speed (ms)
> 
> int shortestHueStep(float startH, float endH) {
> float diff = endH - startH;
> 
> if (diff > 180.0f) diff -= 360.0;
> else if (diff < -180.0f) diff += 360.0;
> 
> return (diff > 0) ? 1 : (diff < 0) ? -1 : 0;
> }
> 
> void fadeToTarget() {
> float lStep = (targetL - currentL) / fadeSteps;
> 
> for (int i = 0; i < fadeSteps; i++) {
> 
> currentL += lStep;
> 
> RGB color = hsvToRgb(currentH, currentS, currentL);
> 
> int oldcolorr, oldcolorg, oldcolorb;
> if (oldcolorr != color.r || oldcolorg != color.g || oldcolorb != color.b) {
> Serial.print("r ");
> Serial.print(color.r);
> Serial.print(" g ");
> Serial.print(color.g);
> Serial.print(" b ");
> Serial.println(color.b);
> oldcolorr = color.r;
> oldcolorg = color.g;
> oldcolorb = color.b;
> }
> 
> analogWrite(rPin, color.r);
> analogWrite(gPin, color.g);
> analogWrite(bPin, color.b);
> 
> delay(fadeDelay);
> 
> }
> 
> currentH = targetH;
> currentS = targetS;
> currentL = targetL;
> }
> 
> RGB hsvToRgb(float h, float s, float v) {
> s /= 100.0f;
> v /= 100.0f;
> 
> float r = 0, g = 0, b = 0;
> 
> if (s == 0) {
> r = g = b = v;
> } else {
> h = fmod(h, 360.0f);
> if (h < 0) h += 360.0f;
> float hf = h / 60.0f;
> int i = (int)floor(hf);
> float f = hf - i;
> float p = v * (1.0f - s);
> float q = v * (1.0f - s * f);
> float t = v * (1.0f - s * (1.0f - f));
> 
> switch (i) {
> case 0: r = v; g = t; b = p; break;
> case 1: r = q; g = v; b = p; break;
> case 2: r = p; g = v; b = t; break;
> case 3: r = p; g = q; b = v; break;
> case 4: r = t; g = p; b = v; break;
> case 5: default: r = v; g = p; b = q; break;
> }
> }
> 
> RGB color;
> color.r = (uint8_t)round(r * 255.0f);
> color.g = (uint8_t)round(g * 255.0f);
> color.b = (uint8_t)round(b * 255.0f);
> return color;
> }
> 
> void handleCommand() {
> if (IrReceiver.decode()) {
> switch (IrReceiver.decodedIRData.decodedRawData) {
> case 0x5DA2FF00 : // POWER for full bright white
> targetH = 0 ;
> targetS = 0 ;
> targetL = 100;
> break;
> 
> case 0x3DC2FF00 : // undo for all lights off
> l = 0 ;
> break;
> 
> case 0xCF30FF00: // red
> targetH = 0;
> targetS = 100;
> targetL = 100;
> break;
> 
> case 0xE718FF00: // green
> targetH = 120;
> targetS = 100;
> targetL = 100;
> break;
> 
> case 0x857AFF00: // blue
> targetH = 240;
> targetS = 100;
> targetL = 100;
> break;
> 
> case 0X1FE0FF00: // brightness down
> targetL = max(50, targetL - 1);
> break;
> 
> case 0x6F90FF00: // brightness up
> targetL = min(100, targetL + 1);
> break;
> 
> default: break;
> }
> 
> // weer omzetten in rgb
> 
> fadeToTarget();
> 
> 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();
> }
> 
> ```

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

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