# LED Brightness, for(), dash board slider, dimming

**URL:** <https://discourse.nodered.org/t/led-brightness-for-dash-board-slider-dimming/28706>\
**Category:** General\
**Created:** [22 June 2020 02:46 UTC](https://discourse.nodered.org/t/led-brightness-for-dash-board-slider-dimming/28706 "2020-06-22T02:46:58Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![seyeon](https://avatars.discourse-cdn.com/v4/letter/s/3bc359/32.png) [@seyeon](https://discourse.nodered.org/u/seyeon)\
**Post date:** [22 June 2020 02:46 UTC](https://discourse.nodered.org/t/led-brightness-for-dash-board-slider-dimming/28706/1 "2020-06-22T02:46:58Z")

</div>

![스크린샷 2020-06-22 오전 11.29.39](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/1/2108787bc7588aaafb23cdccbbeae2bbf12de57f.png)

How can I slowly increase the brightness of a light in Node-red?.

apply for() to the Dashboard with slider...Or what else?

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [22 June 2020 05:57 UTC](https://discourse.nodered.org/t/led-brightness-for-dash-board-slider-dimming/28706/2 "2020-06-22T05:57:44Z")

</div>

To send msg in a loop you can use `node.send`, eg;

```auto
s = msg.payload

for(x=s;x<255;x++){
  node.send({"brightness":x})
}

```

Then add a delay node, set it rate limit 1 per second, or a fraction; 0.2

 ![Screenshot 2020-06-22 at 07.57.11](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/d/ad0402fcf18d872a25464e40eb8ad2cdeaa9d93f.jpeg)

Example flow

```auto
[{"id":"230ec9aa.d10f3e","type":"inject","z":"46161f77.3c21d","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"payload":"200","payloadType":"num","x":250,"y":500,"wires":[["dd0be8e0.063e98"]]},{"id":"dd0be8e0.063e98","type":"function","z":"46161f77.3c21d","name":"","func":"s = msg.payload\n\nfor(x=s;x<255;x++){\n\n node.send({\"brightness\":x})\n\n}\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":400,"y":500,"wires":[["cec8de22.da0a4"]]},{"id":"e19bad9a.a09f98","type":"debug","z":"46161f77.3c21d","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":710,"y":500,"wires":[]},{"id":"cec8de22.da0a4","type":"delay","z":"46161f77.3c21d","name":"","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"0.5","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":550,"y":500,"wires":[["e19bad9a.a09f98"]]}]

```

---

<div class="post-metadata">

**Author:** ![seyeon](https://avatars.discourse-cdn.com/v4/letter/s/3bc359/32.png) [@seyeon](https://discourse.nodered.org/u/seyeon)\
**Post date:** [22 June 2020 08:33 UTC](https://discourse.nodered.org/t/led-brightness-for-dash-board-slider-dimming/28706/3 "2020-06-22T08:33:30Z")

</div>

![스크린샷 2020-06-22 오후 5.15.04](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/7/0733e1ad43b49692f6b2b9125d1f6f222beff914.png)

Thank you for answering my questions.  
I'm a beginner and studying.  
I did it exactly the same. But The output data keeps generating errors.  
Do you know why? 😭

Can I just send out number?

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [22 June 2020 08:49 UTC](https://discourse.nodered.org/t/led-brightness-for-dash-board-slider-dimming/28706/4 "2020-06-22T08:49:27Z")

</div>

Set the debug node to output 'complete msg object'

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [22 June 2020 08:52 UTC](https://discourse.nodered.org/t/led-brightness-for-dash-board-slider-dimming/28706/5 "2020-06-22T08:52:33Z")

</div>

> [@seyeon](#):
>
> Can I just send out number?

well - `msg.payload` can be just a number - but `msg` cannot - it must be an object.

---

<div class="post-metadata">

**Author:** ![seyeon](https://avatars.discourse-cdn.com/v4/letter/s/3bc359/32.png) [@seyeon](https://discourse.nodered.org/u/seyeon)\
**Post date:** [22 June 2020 09:37 UTC](https://discourse.nodered.org/t/led-brightness-for-dash-board-slider-dimming/28706/7 "2020-06-22T09:37:13Z")

</div>

> [@dceejay](#):
>
> well - `msg.payload` can be just a number - but `msg` cannot - it must be an object.

To receive data with dashboard sliders, it must be transformed into numbers.  
Is there any other way...? 😢

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [22 June 2020 09:43 UTC](https://discourse.nodered.org/t/led-brightness-for-dash-board-slider-dimming/28706/8 "2020-06-22T09:43:12Z")

</div>

yes - use a change node ? move msg.payload.brightness to msg.payload ?

---

<div class="post-metadata">

**Author:** ![seyeon](https://avatars.discourse-cdn.com/v4/letter/s/3bc359/32.png) [@seyeon](https://discourse.nodered.org/u/seyeon)\
**Post date:** [23 June 2020 02:55 UTC](https://discourse.nodered.org/t/led-brightness-for-dash-board-slider-dimming/28706/10 "2020-06-23T02:55:22Z")

</div>

![스크린샷 2020-06-23 오전 11.50.19](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/5/65c0b9f514776f027915f87fd1898fbf6bb5c8e2.png)

Eveything worked out the best  
(+ I changed. brightness \> bright)

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [23 June 2020 05:29 UTC](https://discourse.nodered.org/t/led-brightness-for-dash-board-slider-dimming/28706/11 "2020-06-23T05:29:30Z")

</div>

Sorry, but I have to ask:

```auto
s = msg.payload

for(x=s;x<255;x++){
  node.send({"brightness":x})
}

```

The `for(x=s;x<255;x++){`

Ok, I get it that x has to be set to what was sent in as the starting point - I'm guessing.

But the `x=s` is inside the `for`. So why isn't it stuck with x being 200?

Yeah, I'm stupid. This has been well established.

I'm not upset / angry / (what ever) with you for posting it. It works.

But I can't see the **how**.

Is it that the `x++` only goes back to the previous part where it is `x<255`?

Anyway, thanks in advance.  
(I hope.) 😉

Oh, and P.S.  
Aren't you forgetting the `let` or `var` in the first line for `s`?

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [23 June 2020 06:00 UTC](https://discourse.nodered.org/t/led-brightness-for-dash-board-slider-dimming/28706/12 "2020-06-23T06:00:53Z")

</div>

`for( initial; condition; increment ){ statement }`

Initial is the start value upon starting the loop. As long as condition is true, statement is executed after which initial is incremented with the increment value (ie. increment is an expression. ++ means: current value +1)

ie. start at 130, is 130 lower than 255 ? yes, execute and increment with 1 (=131), etc.

> Aren't you forgetting the `let` or `var` in the first line for `s` ?

In javascript it is not required to declare variables (yes it is better practice), if they are not declared, they do require a value to be set, which applies here.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [23 June 2020 06:03 UTC](https://discourse.nodered.org/t/led-brightness-for-dash-board-slider-dimming/28706/13 "2020-06-23T06:03:36Z")

</div>

Thanks.

So

> Is it that the `x++` only goes back to the previous part where it is `x<255` ?

Thanks.

> [@bakman2](#):
>
> In javascript it is not required to declare variables (yes it is better practice), if they are not declared, they do require a value to be set, which applies here.

Sorry, you lost me there to what you mean.

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [23 June 2020 06:10 UTC](https://discourse.nodered.org/t/led-brightness-for-dash-board-slider-dimming/28706/14 "2020-06-23T06:10:19Z")

</div>

> So  
> Is it that the `x++` only goes back to the previous part where it is `x<255` ?

Read it again. the initial value is the starting value and it increments. Loop is stopped when condition is false (ie when x = 256)

> Sorry, you lost me there to what you mean.

```auto
let a // ok - declaration
var a // ok - declaration
let a = 'value' // ok - declaration with a value set
a = 'value' // ok - value set
a // not ok - no declaration and no value set

```

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [23 June 2020 06:18 UTC](https://discourse.nodered.org/t/led-brightness-for-dash-board-slider-dimming/28706/15 "2020-06-23T06:18:55Z")

</div>

Thanks.

The `if( )` but.... Understood. There was confusion to what was meant by me with the:

> Is it that the `x++` only goes back to the previous part where it is `x<255` ?

line.

All good now.

BTW, I'm guessing you are using the new Beta? Y/N?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [7 July 2020 06:28 UTC](https://discourse.nodered.org/t/led-brightness-for-dash-board-slider-dimming/28706/16 "2020-07-07T06:28:24Z")

</div>

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