I have successfully change the color by using the neopixel write() function.
There is a setBrightness() function in the original arduino library,
How can I use the setBrightness() function to change the LED brightness in Espruino?
The most basic approach is to set the value of each RGB element as a percentage of the maximum allowable value. This would be in the range from 0 to 255 decimal the equivalent of 0 to FF hexidecimal. But the percentage isn't a direct ratiometric conversion.
As the eye doesn't perceive brightness as a color intensity level, and also struggles with the differences in color when displayed by a monitor or in this case an LED, there is the need to approximate those values.
Using a standard WS2812B single Neopixel
require("neopixel").write(B15, [255,0,0]); // turn RED LED to full intensity
require("neopixel").write(B15, [0,127,0]); // turn GRN LED to half intensity
require("neopixel").write(B15, [0,0,63]); // turn BLU LED to one quarter intensity
It will soon be discoverd that there seems to be a better ratiometric control when the values are in the lower end of the range. This has to do with the eye's persistence when detecting color differences, and human perceived brightness then is just an approximation of that intensity value.
This is one method of applying a brightness value as a percentage:
var nPcntBr = Math.floor( nRGBvalue * nBrightness / 100 );
Topics to discover, color palette, eye persistence, color Gamma, monitor color rendering, to name a few. There are many excellent tutorials at SparkFun and AdaFruit. Reverse engineering the FastLED module will also provide insight that may assist in getting a near perfect solution.
Thank you Robin for your reply. It's really very helpful for me.
Don't worry about formatting, just type in the text and we'll take care of making sense of it. We will auto-convert links, and if you put asterisks around words we will make them bold.
For a full reference visit the Markdown syntax.
© Espruino, powered by microcosm.
Report a problem