So, it's a bit unclear to me in the docs,

So, it’s a bit unclear to me in the docs, but is there a way to arbitrarily use segments of a LED strip as separate arrays?

I’m currently making a new LED tie - it has 68 LEDs per edge, with 48 down the center, and a NeoPixel ring to cap it off. It’d be nice to define them as left/right/center/ring arrays - and it’d be extra cool if for the Right side, I could define it backwards - LEDS 136 - 69, so it’d automagically be opposite the other side.

I can’t answer your question, but I had to comment on the tie. That sounds great!! I hope you’ll post video of it when it’s finished.

I’m still working out some layout issues - the tip of the tie is looking a bit sloppy, and it looks like I need to redo it, as if I can manage to fit 1 extra pixel on the right side, it’ll make it more symmetrical. As it is, LED 69 is the very tip, so the actual layout is 68/1/67/48/16.

… I think I can put a 8px Adafruit stick in place of a 7px strip. I just hope it’s not too glaring a spacing change.

I wanted to arrange an LED strip into ‘zones’ where each zone behaved differently - so for example zone A was a fixed colour, zone B showed a changing pattern, zone C was fixed, etc.

Please excuse my extremely ugly code…

#include <FastLED.h>

#define DATA_PIN 6 // Arduino data pin > WS2812B
#define TYPE WS2812B // LED String type according to FastLED
#define ORDER GRB // Define colour display order - WS strings are GRB

#define NAV 5 //How many pixels for NAV area
#define Area_Size 32 //How many pixels per area total (including NAV)
#define NUM_LEDS Area_Size*4 // size of LED String
#define BRT 15 // Set overall brightness 1-255


#define Area_NA 0 //Start of Nav Area A
#define Area_NB Area_Size*1 //Start of Nav Area B
#define Area_NC Area_Size*2 //Start of Nav Area C
#define Area_ND Area_Size*3 //Start of Nav Area D
#define VArea_A Area_NA+NAV //Start of Area A
#define VArea_B Area_NB+NAV //Start of Area B
#define VArea_C Area_NC+NAV //Start of Area C
#define VArea_D Area_ND+NAV //Start of Area D

int NAA[NAV][3];             // Array for Nav Area A
int NAB[NAV][3];             // Array for Nav Area A
int NAC[NAV][3];             // Array for Nav Area A
int NAD[NAV][3];             // Array for Nav Area A

int VAA[Area_Size-NAV][3];             // Array for Variable Area A
int VAB[Area_Size-NAV][3];             // Array for Variable Area A
int VAC[Area_Size-NAV][3];             // Array for Variable Area A
int VAD[Area_Size-NAV][3];             // Array for Variable Area A

CRGB leds[NUM_LEDS];

void setup() {
FastLED.addLeds<TYPE, DATA_PIN, ORDER>(leds, NUM_LEDS); // initialise string
FastLED.showColor(CRGB::Black); // clear LEDs
FastLED.setBrightness(BRT);
}

// set up fixed NAV area
void setNavArea (int a, CRGB c) {
for (int n = a; n <= a+(NAV-1); n++) {
leds [n] = c;
}

}
// set up variable area
void setArea (int a, CRGB c) {
for (int n = a; n <= a+(Area_Size-NAV-1); n++) {
leds [n] = c;
}

}

void copy_led_array(){
for(int i = 0; i < NAV; i++ ) {
ledsX[i][0] = leds[i].r;
ledsX[i][1] = leds[i].g;
ledsX[i][2] = leds[i].b;
}
}

void loop() {

// initialise NAV areas
setNavArea (Area_NA, CRGB::Red);
setNavArea (Area_ND, CRGB::Red);
setNavArea (Area_NB, CRGB::Blue); 
setNavArea (Area_NC, CRGB::Blue);

/* initialise variable areas
setArea (VArea_A, CRGB::Aqua);
setArea (VArea_B, CRGB::Yellow);
setArea (VArea_C, CRGB::White);
setArea (VArea_D, CRGB::Coral); */

FastLED.show();
delay(500);

// Blink Red NAV
setNavArea (Area_NA, CRGB::Black);
setNavArea (Area_ND, CRGB::Black);
// setNavArea (Area_NB, CRGB::Black);
// setNavArea (Area_NC, CRGB::Black);
FastLED.show() ;
delay(500);
}

This is basically a “C” question, which can be paraphrased sort of like this: If I already have one large array, “leds[]”, how can I refer to portions of it as smaller separate arrays, e.g., “rightleds[]”, “centerleds[]”, etc ?

(I’m going to assume the 12-pixel ring)

#define NUM_LEDS (68+48+68+12)
CRGB leds[NUM_LEDS];
#define STARTS_AT(N) (&(leds[N]))
CRGB* rightleds = STARTS_AT(0);
CRGB* centerleds = STARTS_AT(68);
CRGB* leftleds = STARTS_AT(68+48);
CRGB* ringleds = STARTS_AT(68+48+68);

You’ve just defined four new named pointers, each of which points to a particular starting point in your leds[] array. Now you should be able to put anything you like into them as if they were their own array, for example, leftleds[ i ] where i is 0…67.

As for wanting one side reversed, I’d just wire it up facing the way that you wanted and save yourself some coding!

Otherwise, instead of this:
leftleds[ i ] = CRGB:Red;
rightleds[ i ] = CRGB:Red;
you’ll have to write this each time:
leftleds[ i ] = CRGB:Red;
rightleds[ (67 - i) ] = CRGB:Red;

It’s actaully 68/1/68/48/16 - I managed to balance out the sides.

So this way will let me do stuff like fill_rainbow(&(leftleds[0]),68,200)? That’s the part missing from my current method of just making functions to do the pixel setting.

Yep! Thanks to the fact that “arrays” in C are actually just pointers to the first element of the array, that’ll work fine.

That also means that any place you have “&(array[0])” (which should be read as “address of the first element of array”), you can instead just say “array”, since that ALSO means “address of the first element of array”! So that means you an write this, too, which is easier on the eyes:

fill_rainbow( leftleds, 68, 200);

Very cool! I’ve learned something new.

For flipping the right side LEDs over, I’m using this function:

#define SIDESIZE 68

void reverse() {
for (int i = 0,j=SIDESIZE - 1; i<SIDESIZE/2; i++, j–) {
CRGB temp = right[i];
right[i] = right[j];
right[j] = temp;
}
}

and I just call it after I set them. I don’t know if that can get any more efficient, since it’s really only iterating over half the array.

It makes it really easy, since I can just copy left to right, and flip the right side.

Now to make some interesting patterns! wee!