Neopixel Dynamic/Rainbow nested within a Static Strip

Hi

So i'm making a wordclock. I've got my WS2812 LEDs all wired up and working happily to tell the time

The issue is that I want certain LEDs (by position in a single strip) to have a 'rainbow' effect like the Neopixels examples have.

I'm struggling to code in such a way to show the rainbow effect on some LEDs only, while leaving the other static LEDs untouched. I don't seem to be able to do it by defining both 'pixels' and 'strip' and then trying to light the rainbow ones only - the Strip seems to override the Pixel commands used for displaying the time,

Question is: is there a way of showing a rainbow of a certain range of neopixels within a strip without upsetting the static pixels of the rest of the strip?

Or do i need to wire it as two 'items' - a time telling strip and a strip to show rainbows on?

Cheers - Code below as it currently works, without trying to integrate a rainbow section

Yes, all perfectly possible. It's just a matter of coding. You forgot to give us your code. Please do use code tags so it looks like this

Thankyou - the code is here: Wordclock

I have now actually solved this problem by taking the relevant ‘dynamic’ section and putting it on as a new item on a seperate pin, this makes it easier to control.

I theorised I could have the dynamic section within the static section if I refreshed/updated the whole array of pixels every time - but given my code is based on a static background I though it might be easier to resolder.

Anyway, now i’ve got further. The code I have linked to now has a dynamic section which shows a moving rainbow, while the time telling is on a seperate pin.

I’m stuck with the following - I set the rainbow to do multiple strips depending on the words. e.g. the following runs the rainbow LED 5 to 12

 for(i=5; i<12; i++)

I’m having an issue where it is running each word independently and the other dynamic words stop.

Is there a way to specify a non-contiguous range of numbers for my ‘i’ value?

I’m aiming for something like this;

(i=0-5, i=13-24; i++) or (i=0,1,2,3,4,5,13,14,15,16,…)

but I don’t know the correct syntax to run a non-contiguous set. Could you give me a pointer?

Is there a way to specify a non-contiguous range of numbers for my ‘i’ value?

No.

What you do is have the loop variable run from zero to the number you want, and convert that into the LED to use with an array. So something like:-

lookUp[] ={0,1,2,3,4,5,13,14,15,16,.....};
for( i =0; i < 12; i++) {
LedToUse = lookUp(i);
LedToUse = lookUp[i];

Thanks, but i’m 'm afraid I don’t quite understand how to implement

The code I have is as follows:

void showHappyBirthday() {
  uint16_t i, j;

  for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
    for(i=0; i<13; i++) {
      strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
    }
    strip.show();
    delay(10);
  }
}

and it cycles between LEDS 0 and 13 happily.

I’m afraid I don’t understand where and how to put the lookup function. I think I understand what you’re doing - you’re defining an array of LEDS of my choice {1,2,9,12…} and then calling that array for i. I don’t understand the coding well enough to know where to put this though.

Should I define the LED array in (void)setup?

You asked:-

Is there a way to specify a non-contiguous range of numbers for my ‘i’ value?

and I told you ( plus PaulRB’s correction - thanks )

Should I define the LED array in (void)setup?

No. Define it outside any function then that makes it a global array and available to any function.

I’m afraid I don’t understand where and how to put the lookup function.

Where you wanted to put
Quote from reply #2
(i=0-5, i=13-24; i++) or (i=0,1,2,3,4,5,13,14,15,16,…)
You put

for( i =0; i < 12; i++) {
LedToUse = lookUp[i];

and then calling that array for i.

No you do not call the array, you use it to convert i into the LED number you want it to be.

I have no idea how you want to change the operation of that function you just posted because you have not said what you want it to do.

Sorry, I think i’ve jumped around a bit - i’ve been trying to operate on principles and understanding it further rather than having an answer telegraphed. Most of the trial and error I carry out in Strandtest to understand it before putting it into my real code.

I want this function:

void showHappyAnniversary() {
  uint16_t i, j;

  for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
    for(i=13; i<22; i++) {
      strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
    }
    strip.show();
    delay(10);
  }
}

to light a non-contiguous range of neopixel LEDs - namely pixels 0 to 5 and 13 to 25. Currently I can make it call any contiguous range with no problems (example shows 13 to 22 lit).

I’ve been working on effecting your posted solution (thanks) but it keeps giving me errors. I’ve spent some time reading about arrays and integrating into for but I still don’t understand.

If I put:

lookUp[] ={0,1,2,3,4,5,13,14,15,16,17,18,....};

into the top of the page before void setup (this is what you mean by outside any function I believe) then the program just returns ‘lookUp’ does not name a type as an error. Do I need to preface it with ‘int’ or ‘char’?

I also get an error: ‘ledtouse’ is not declared in this scope. Do I need to somehow define all the LEDs within the array first?

Sorry, i’ve been going round in circles with arduino’s array page and other third party pages and I still don’t understand how to code it, although I think I understand the underlying principle.

Finally got it (in strandtest)

I didn’t realise I had to call the values of the relevant pixels in the strip.setpixelcolour - I thought I was trying to push them backwards into the ‘for’ function.

int happyanniversary[] ={0,1,2,3,4,13,14,15,16,17,18,19,20,21,22,23,24};


void showHappyAnniversary() {
  uint16_t i, j;

  for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
    for(i=0; i<17; i++) {
      strip.setPixelColor((happyanniversary[i]), Wheel(((i * 256 / strip.numPixels()) + j) & 255));
    }
    strip.show();
    delay(10);
  }
}

Thanks for your help both of you - I was reading your code wrong and though the '‘LEDsToUse’ was a new line to be added rather than a reference to my existing code.

I was fundamentally misunderstanding the code - I thought the line

for(int i=0; i<6; i++)

was where I chose which LEDs to light, not the line after it.