# Running Light with Neopixel

**URL:** https://discourse.nodered.org/t/running-light-with-neopixel/12284
**Category:** General
**Created:** [16 June 2019 13:42 UTC](https://discourse.nodered.org/t/running-light-with-neopixel/12284 "2019-06-16T13:42:20Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Danieldz](https://avatars.discourse-cdn.com/v4/letter/d/50afbb/32.png) [@Danieldz](https://discourse.nodered.org/u/Danieldz)
#### Post date: [16 June 2019 13:42 UTC](https://discourse.nodered.org/t/running-light-with-neopixel/12284/1 "2019-06-16T13:42:20Z")

</div>

Hey Guys,  
I am still pretty new to Node Red, but I somehow like it already. I am helping a friend a I am now into the controlling of a Neopixel strip. The Basic function, that i wanna realize is, that I have a Timestamp with an interval of 70ms ( it sends every 70 ms a true as payload). Then I want to have a function element which increases everytime a variable by 1. So when I start the variable starts with 0 and sents to Neopixel 0 a color. after 70ms its a 1 and sents to Neopixel 1 a color. and so on until it reaches 6. I have no idea how to realize it in the function block. Hope you can help.

A kind of different question is: A friend of mine has a bigger project and there will be more questions about node red. Shall I open a Topic for the Project and just put all the questions in there? And if we done, I cann put the code in here, maybe it helps someone else?

Thanks anyways.

All the Best  
Danieldz

---

<div class="post-metadata">

### Author: ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)
#### Post date: [16 June 2019 13:58 UTC](https://discourse.nodered.org/t/running-light-with-neopixel/12284/2 "2019-06-16T13:58:51Z")

</div>

> [@Danieldz](#):
>
> Then I want to have a function element which increases everytime a variable by 1. So when I start the variable starts with 0 and sents to Neopixel 0 a color. after 70ms its a 1 and sents to Neopixel 1 a color. and so on until it reaches 6. I have no idea how to realize it in the function block. Hope you can help.

You will need a temporary variable that keeps track of the count. You can do this nicely in a function node by using a `context` variable.

```auto
// Get the counter variable from store or give zero if the variable doesn't yet exist
let counter = context.get('mycounter1') || 0

// Add 1 to the counter
counter++

// Write the counter back to the store
context.set('mycounter1', counter)

// output a msg with the new count
msg.payload = counter

return msg

```

NB: the code above is untested.

> [@Danieldz](#):
>
> bigger project and there will be more questions about node red. Shall I open a Topic for the Project and just put all the questions in there?

You will generally get the best reception by trying things yourselves and then raising specific questions. Long, complex questions get less help because people don't have the time or energy to wade through them as much.

> [@Danieldz](#):
>
> And if we done, I cann put the code in here, maybe it helps someone else?

There is a section for sharing your projects which you can use. It is also nice to add them to the Flows site (see the menu at the top of this site). so that people can easily reference them in the future.

---

<div class="post-metadata">

### Author: ![Danieldz](https://avatars.discourse-cdn.com/v4/letter/d/50afbb/32.png) [@Danieldz](https://discourse.nodered.org/u/Danieldz)
#### Post date: [24 June 2019 11:55 UTC](https://discourse.nodered.org/t/running-light-with-neopixel/12284/3 "2019-06-24T11:55:21Z")

</div>

Thank you very much for your help. Your Comments are really good.  
I am slowly understanding the things. I will try the code and give a feedback than.

Have a wonderful week

Danieldz
