Fast LED light pattern generation help

Posted on
  • I'm in the process of trying to make an LED coat like this one for a party next week. I'm driving 500 WS2811s with this poor little espruino pico because it's all I've got right now. I have no issues with powering them all, I have that figured out. What I am struggling with is generating the patterns. Too much math is happening to push out 3*500 random numbers to make the LED light change snappy. Basically it's a slideshow. It all works fine, just slow as hell.

    What I want to do is either output a 25 light pattern x 20, but I can't figure out how (or if its even possible).

    Anyone have any advice on how to do it? I thought about concatenating the array into a larger array (thus saving a bunch of math steps), or just trying to output the same array multiple times in one go using require("neopixel").write but cant seem to make it happen.

    If there is no solution, I'll just use static patterns, but it would be cool for them to be animated.

    Pic attached for desired outcome.


    1 Attachment

    • 315524475_925069888460378_6624888533066177187_n.jpg
  • Cool - To speed things up you can add "compiled"; to your random value generator function like explained here JavaScript Compilation

  • Thanks so much for this! I'll let you know how it goes!

  • What I want to do is either output a 25 light pattern x 20

    You could try this:

    // make my pattern
    pattern = new Uint24Array(25);
    for (var i in pattern) 
      pattern[i] = E.HSBtoRGB(i*0.1,1,1) ; // or whatever you need for some RGB stuff
    
    require("neopixel").write(pin, E.toUint8Array({data:pattern.buffer, count:20}));
    
    // this may also work - but i'm not 100% sure:
    require("neopixel").write(pin, {data:pattern.buffer, count:20});
    

    Uint24Array isn't actually in the JS spec, but it's super helpful for neopixels as you can write R/G/B in one go.

    As @MaBe mentioned you can also try compiled code when you're calculating what your 25 LED pattern should be.

    Note that you could also do stuff like:

    pattern = new Uint24Array(25);
    rpattern = new Uint24Array(25);
    // ...
    rpattern.set(pattern);
    rpattern.reverse();
    
    E.toUint8Array({data:[pattern.buffer,rpa­ttern.buffer], count:10})
    

    So then it does the pattern, but flips and repeats it so even if you start with red and end with green, there's no harsh point at which it changes

  • So I know this thread is super old but I wanted to say thanks to @Gordon that was the trick I was looking for!

    I was able to use it also to make a sound reactive LED hat using some advice you gave someone else! Thanks for helping me as I am new to the coding world!

  • If you establish some pattern beforehand, you can pick by algorithm or random and push out as @Gordon sugget. When you want to move things around within chosen pattern or splice things together, you can use algorithms written in C, as I did in Efficiently moving things around in zig-zag Graphics buffer visualized w/ 24/32 bpp displays / neopixel strings. The referenced example uses the graphics buffer that is suppoted with graphics functions. The graphics functions are used to write to the buffer, and an intervalled process writes it out to the LED string(s). The arrangement of your LEDs are like the surface of a cylinder which is just lime a bent dot matrix screen on which you can draw things on.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Fast LED light pattern generation help

Posted by Avatar for AdaMan82 @AdaMan82

Actions