Hey guys! I've posted on this forum before like a year ago, got help,

Hey guys! I’ve posted on this forum before like a year ago, got help, was content with my setup, but now want to do more. I have 2 questions, an arduino/c++ based question and a questing regarding FastLED functions. I’ll explain my project so it makes more sense.

I have 450 WS2812B lights around the perimeter of my room. Right now I have an audio jack connected into 2 MSGEQ7 IC’s to read in the audio data. The data consists of 7 frequencies from the left channel and 7 from the right. I have successfully made an audio spectrum analyzer, but am running into issues when I increase the size of the frequency “blocks”. I currently have a 1x14 setup, with each led corresponding to a frequency value…but I have 450 leds available. I decided to expand to a section 42 leds long, to test my code as well as the power draw.

  1. I have defined my leds in an array, such that
    CRGB leds[num_leds];
    I have defined the led numbers I want for each block in arrays as well
    int left_63[] = {1,2,3};
    int left_160[] = {4,5,6};
    int left_400[] = {7,8,9};
    and so on. I run into an issue when I try to change the elements of the array all at once; I want led #'s 4, 5, and 6 to all change at once without the use of a for loop. I do this by declaring
    leds[left_63] = CHSV(192,255,spectrum_left[0]);
    leds[left_160] = CHSV(180,255,spectrum_left[1]);
    leds[left_400] = CHSV(128,255,spectrum_left[2]));
    and so on. This presents an error stating
    “invalid types ‘int[int]’ for array subscript”
    How do I fix this? I know what I want to do, I am unsure how to get c++ to perform this operation and I am unsure what to google as I am still a novice with c++.

  2. To negate the issue from problem 1, I decided to do something different in the main loop. I decided the best method was to use a for loop to re-write each array one at a time
    for (int i =1; i <= 3; i++){
    leds[i] = CHSV(192,255,spectrum_left[0]);
    leds[i+3] = CHSV(180,255,spectrum_left[1]);
    leds[i+6] = CHSV(128,255,spectrum_left[2]));
    }
    and so on. I start running into issues when I increase the size of the “blocks”. So if I make i <= 32, the clock on the arduino cannot keep up with the huge computational requirement, meaning my lights lag behind and each “block” slowly updates (like an old CRTV). I decided to use one of the builtin FastLED functions to fix this
    fill_solid(leds,42,CHSV(192,255,spectrum_left[0]));
    fill_solid(leds,39,CHSV(180,255,spectrum_left[1]));
    fill_solid(leds,36,CHSV(128,255,spectrum_left[2]));
    and so on. My question with this: Is there a function in the FastLED library where I can fill a certain section of lights at once instead of everyone up to the specified number? Something like
    fill_solid(leds,39 through 42,CHSV…);
    fill_solid(leds,36 through 39, CHSV…);

I hope I outlined my questions/problems in an easy to understand manner, and hopefully there’s an easy fix! Thanks again!
Griff

I think that CRGBArray is the answer to your second question. Ignore the as l warnings, it works perfectly now.

@Griff_Malloy to answer your first question. You cannot do that in C or C++ ;(
I am quite surprised that you are running into computing issue with I<=32. You have 8Mhz or 16Mhz cpu. It should not be of any problem in theory. Could you publish the code of the complete sequence of the block update ?
I say that because the fill_solid function is nothing more than a loop function for(i…)

To answer your second question
You should be able to to this
fill_solid(&leds[39],4,color) to fill from 39 till 42
Hope this help

@Yves_BAZIN I put my code on Pastebin for you to look at. The line where I was getting the update lag is on lines 79-95. I went ahead an took the suggestion from Jeremy Spencer, creating the sequence in a CRGBArray on line 15. For whatever reason, this fixed the issue with the update lag… I call to the CRGBArray with the function “LEDS_write()” on line 76, maybe my untrained eye missed something in the old loop which caused the lag error.

I am using an Arduino Elegoo Uno R3

https://pastebin.com/Dt29C82C

Thanks again!
Griff

@Griff_Malloy hello except that your Loop should do (for i=0;i<10;i++) I don’t see why this is slow.
My guess is that the loop is making memory access trying to find each time the value of the array of the mseq7.

@Yves_BAZIN Ok. Isn’t this what you said fill_solid() does? Maybe the code and the fast math in FastLED makes the loop run faster…? Anyways, thanks for the help!

@Griff_Malloy in the fill solid you do not retrieve a different value in a array everytime but each time copying the same value which becomes a constant for the function. Like in you leds(x,y)=color. You retrieve the color only once not three times. In your loop you need each times to retrieve each loop 14 different values from the memory.
I guess if your were to save the values in set of variables before the loop then you will not have the issue.
Look for the fill_solid function within the fastled library.