Really struggling creating new patterns for multiple array setup.

Really struggling creating new patterns for multiple array setup. Wondering if anyone can help me get over the hump because I’m clearly missing something important and fundamental in my basic understanding.

I have a new pattern I’m trying to create called “spiral”. I figured I’d start with an extremely basic idea just to get my head wrapped around how to send data not just to [i] pixel on one strip but now to strip [x] and pixel [i]. Spiral was just supposed to light pixel 1 on strip one, wait a bit, fadetoblack, light pixel 2 on strip 2, wait a bit, fadetoblack and so on. The strips are arranged like spokes, hence “spiral”. The full sketch is posted to gist below but here’s the critical snippit, based on the multiple arrays example that moves a dot around and a little color change. I’ve tried to move add or remove the delay, remove the fade, change the format of the fade function. All 8 strips light and stay solid with what I assume is the first random hue. I’m sure I’m missing something simple here:

void spiral()
byte dothue = 0;

for(int i = 0; i < NUM_LEDS_PER_STRIP; i++) {
for(int x = 0; x < NUM_STRIPS; x++) {
// This inner loop will go over each led in the current strip, one at a time

leds[x][i] += CHSV( gHue + random8(64), 200, 255);
dothue += 32;
    EVERY_N_MILLISECONDS(1000) {                           // FastLED based non-blocking delay to update/display the sequence.
    leds [x][i].fadeToBlackBy( 64 );



It looks like you’re adding a random color to every LED every time, but only fading them once per second. Try something like this:

Thanks Jason!! Part of me is tempted to just paste your code in and forget about it but then I wouldn’t learn anything. I understand what yours is doing (I think) but I still don’t really understand why mine wasn’t working? Did I introduce (another) sync issue by lighting the LEDs once per loop but only dimming them once a second? Would it have worked if I simply lowered the delay time?

Your strips light up solid because every frame you’re adding color to every LED. You’re only dimming them once per second, which isn’t enough to overcome the color you’re adding.

Everything in your spiral function is happening every frame, effectively simultaneously. The LEDs only actually update when you call in the loop function. To make your spiral function work how you want, you would need to call and then use the delay function to wait inside your loop.

I always try to avoid calling delay because it can prevent other things from happening, like button presses, IR, wi-fi requests, etc.

So you basically switched it around then right? Instead of lighting the led every frame, you introduce the fade every frame. The leds light every 1 second now instead of trying to dim every 1 second.

Two more follow-ups, sorry, and thank you again!

  1. Why did you need to introduce the new stripindex and dotindex variables? Why would X and I not work in that second part?

  2. You said you try to avoid calling a delay. Do you mean an actual delay function or is the EVERY_N_MILLISECONDS(1000) a bad way to do it as well?

No problem, glad you want to learn! I am definitely still learning, and hope to never stop. :slight_smile:

Yeah, exactly, I just switched it around.

  1. I added stripIndex and dotIndex to keep track of which strip and led should currently be lit. You said you just wanted one led lit at a time, then the next led on the next strip. I made them static inside the function, which means they’ll hold their values between calls to the function.

  2. You should just try to avoid using the actual delay function. The EVERY_N_MILLISECONDS macro doesn’t actually delay. The spiral function will get called every frame, but the code inside the EVERY_N_MILLISECONDS block will only get executed on the interval specified.

Ok, I think that makes sense and was something I hadn’t really understood before. The static variable surviving the loop was new to me. I assumed it always did. That helps to clarify quite a few things actually. What then, is happening with i? Is it running the fadeby function for each led individually all in a single run through the loop? I always assumed that i++ happened each loop but based on how you’ve described it, that goes through the entire strip (all the i’s) in one pass. (mind blown! Ha!) You can see why this has gone so wrong for me up to this point! As I suspected, I was missing some fundamental understanding. Obviously brand new to coding.

Wouldn’t it be a lot easier if the fadeby function could just operate on an entire strip rather than on individual leds?

I have an awful feeling that after figuring this all out, I won’t even like it but at least I will have learned something in the process. I suspect what I’m envisioning would actually need to light not just led #4 but rather leds 0-4 when it gets to that strip. So like a “filled” spiral. That will probably be next. We’ll see.

Who knows if it will actually end up looking cool or not but at least I’m learning!