Rainbow Colors on WS2812

To set the right colors for an RGB LED we have to set the appropriate values for R(ed), G(reen) and B(lue).

colorsOn this website I found this image explaining the composition of colored light from R, G and B.

You can step over the ratio axis and can generate all colors building a rainbow beginning from Red over Yellow, Green and Blue to Magenta and back to Red again.

If you start with three data points then you will get Red (0), Green (1/3) and Blue (2/3) only. The more equidistant data points are used, the finer the color gradation.

The required data points can be calculated with the Cosinus function to get a table of RGB values for controlling a RGB LED or Neopixels etc.

If you want to use the NodeMCU device to calculate the required data points then you will miss the Cosinus function math.cos() which is not implemented in NodeMCU. You can approximate the Cosinus function by a Triangle function or you use a mature Lua version on a host device like PC, Mac or Linux device.

I went the second way. I built the program buildTable.lua on my PC with Lua for Windows. This program generates the required data points and writes them into a data file rainbow.dat. This data file can be transferred to the NodeMCU device. The file rainbow1.lua loads these data points and uses them to control a WS2812 RGB LED. The file rainbow.lua has a fix data set included and can be used for simple tests, too. You will find these files on Github and Sourceforge.

Advertisements
Rainbow Colors on WS2812

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s