As the title says... Chat on...

User avatar
By RFZ
#57731 Hi,
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:

Code: Select all        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);
        end


I'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:

Code: Select all    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;
    end


Takes 40ms :/

Is LUA / NodeMCU really that bad performance, or is my code / the library just crap?