I want to somehow animate 59 WS2812 LEDs. One animation should be to cycle all RGB colors on each segment, which is done by this code:
for l = 1,leds do
g,r,b = ledhighbuf:get(l);
h,s,i = luacolors.RGBtoHSL(r,g,b);
r,g,b = luacolors.HSLtoRGB((h+math.random(5))%360,255,127);
ledhighbuf:set(l,g,r,b);
endI'm using the luacolors lib ( https://github.com/icrawler/luacolors ) to convert RGB to HSL so it is easier to cycle through the color wheel.
However, this part of the code takes already 75ms to execute!
Fading to a target value, like this:
for l = 1,leds do
local g,r,b = ledbuf:get(l);
local gt,rt,bt = ledtbuf:get(l);
g = math.floor(g + (gt-g)/4);
r = math.floor(r + (rt-r)/4);
b = math.floor(b + (bt-b)/4);
ledbuf:set(l,g,r,b);
g,r,b,gt,rt,bt = nil;
endTakes 40ms :/
Is LUA / NodeMCU really that bad performance, or is my code / the library just crap?