Reading elements in crgb array

This thread is going nowhere. The original request was unclear and @ski113 hasn't provided any further details nor posted any valid code. At this point figuring out what's required is merely guesswork.

Apologies to all. My account was suspended due to my error.

So I was able to get everything to work with suggestions from a few of you.

My misunderstanding of the array and attempting to read parameters that were not there was the main problem. After discovering this I did get the pointer to the array working although with my new understanding I really did not need it.

There were a few things that I was told that I could not do, and they worked fine. I have to admit the original idea was from chemdoc77 on github.

Thanks for all the advice. My updated code is attached, with a number of led effects. The point of this is for a multi ring christmas tree. I set the params in this code for an 8x8 esp32 waveshare matrix until I put the actual tree together.

// Testing FastLED's CRGBSet array function and using it with the fill_solid and fill_rainbow functions.
// credit to Chemdoc77 for the framework and inspiratiion

#include "FastLED.h"
#define NUM_LEDS 30
#define Data_Pin 14
#define chipset NEOPIXEL
#define BRIGHTNESS 5

CRGB rawleds[NUM_LEDS];
CRGBSet leds(rawleds, NUM_LEDS);

byte strip_start[] = { 0, 9, 18, 27 };
byte strip_length[] = { 7, 5, 3, 1 };

//CRGBSet leds1(leds(0, 6));
CRGBSet leds1(leds(strip_start[0], strip_start[0] + strip_length[0] - 1));
CRGBSet leds2(leds(strip_start[1], strip_start[1] + strip_length[1] - 1));
CRGBSet leds3(leds(strip_start[2], strip_start[2] + strip_length[2] - 1));
CRGBSet leds4(leds(strip_start[3], strip_start[3] + strip_length[3] - 1));
//CRGBSet leds2(leds(9, 13));
//CRGBSet leds3(leds(18, 20));
//CRGBSet leds4(leds(27, 27));
//CRGBSet leds5(leds(35, 35));

struct CRGB* ledarray[] = { leds1, leds2, leds3, leds4 };
uint8_t NUM_STRIPS = 4;

CRGB CRGBColorArray[] = { CRGB::Red, CRGB::Green, CRGB::Blue };
uint8_t NumColors = sizeof(CRGBColorArray) / sizeof(CRGBColorArray[0]);

const int ARRAY_PIXELS = 28;
int PixelArray[ARRAY_PIXELS];

//-------------
//-------------


void setup() {

  Serial.begin(9600);

  delay(2000);  // power-up safety delay
  FastLED.addLeds<chipset, Data_Pin>(leds, NUM_LEDS);
  FastLED.setBrightness(BRIGHTNESS);
  FastLED.setMaxPowerInVoltsAndMilliamps(5, 1500);
  set_max_power_indicator_LED(13);
}

void FillRandomized(uint32_t wait, int iterations) {

  for (int i = 0; i < iterations; i++) {

    for (uint8_t colorIdx = 0; colorIdx < NumColors; colorIdx++) {

      InitPixelArrayRand();

      for (int x = 0; x < ARRAY_PIXELS; x++) {
        int target_led = PixelArray[x];

        for (int lstrip = 0; lstrip < NUM_STRIPS; lstrip++) {
          if (target_led >= strip_start[lstrip]
              && target_led < strip_start[lstrip] + strip_length[lstrip]) {

            int l_col = target_led - strip_start[lstrip];

            ledarray[lstrip][l_col] = CRGBColorArray[colorIdx];
            FastLED.show();
            FastLED.delay(wait);
          }
        }
      }
    }
  }
}

void fillSolidInstantly(CRGB Color) {

  for (uint8_t strip_num = 0; strip_num < NUM_STRIPS; strip_num++) {
    fill_solid(ledarray[strip_num], strip_length[strip_num], Color);
    FastLED.show();
  }
}


void fillSolid(int wait, bool delayByStrip, int iterations) {

  for (int i = 0; i < iterations; i++) {

    for (uint8_t colorIdx = 0; colorIdx < NumColors; colorIdx++) {
      for (uint8_t strip_num = 0; strip_num < NUM_STRIPS; strip_num++) {
        fill_solid(ledarray[strip_num], strip_length[strip_num], CRGBColorArray[colorIdx]);
        FastLED.show();

        if (delayByStrip)
          FastLED.delay(wait);
      }
      if (!delayByStrip)
        FastLED.delay(wait);
    }
  }
}

void nblendU8TowardU8(uint8_t& cur, const uint8_t target, uint8_t amount) {
  if (cur == target) return;

  if (cur < target) {
    uint8_t delta = target - cur;
    delta = scale8_video(delta, amount);
    cur += delta;
  } else {
    uint8_t delta = cur - target;
    delta = scale8_video(delta, amount);
    cur -= delta;
  }
}

void fade(CRGB& current, const CRGB& target, uint8_t amount) {
  nblendU8TowardU8(current.red, target.red, amount);
  nblendU8TowardU8(current.green, target.green, amount);
  nblendU8TowardU8(current.blue, target.blue, amount);
}

void fadeAll(int fade_interval, int wait, int iterations) {

  for (int i = 0; i < iterations; i++) {
    CRGB currentColor = CRGBColorArray[0];
    CRGB targetColor = CRGBColorArray[1];
    int targetColor_idx = 0;

    for (uint8_t colorIdx = 0; colorIdx < NumColors; colorIdx++) {
      if (colorIdx < NumColors - 1) {
        targetColor_idx = colorIdx + 1;
        ;
      } else {
        targetColor_idx = 0;
      }

      targetColor = CRGBColorArray[targetColor_idx];

      for (int i = 0; i < 256; i++) {

        // Fade towards blue by 5 steps (0-255)
        fade(currentColor, targetColor, 5);
        // Apply to all LEDs

        for (uint8_t strip_num = 0; strip_num < NUM_STRIPS; strip_num++) {
          fill_solid(ledarray[strip_num], strip_length[strip_num], currentColor);
        }

        FastLED.show();
        FastLED.delay(fade_interval);
      }

      currentColor = targetColor;
    }
  }

  FastLED.delay(wait);  // Adjust delay for speed
}

void loop() {
  Serial.println("***********STARTED****");

  bool Initialized = false;

  if (!Initialized) {
    fillSolidInstantly(CRGB::Red);
  }

  delay(5000);
  fadeAll(30, 100, 2);

  FillRandomized(100, 2);
  fillSolid(4000, false, 2);
  fillSolid(700, true, 2);

  Initialized = true;
}

void InitPixelArrayRand() {

  randomSeed(analogRead(A0));

  for (int i = 0; i < ARRAY_PIXELS; i++) {
    PixelArray[i] = i;
  }

  shuffleArray(PixelArray, ARRAY_PIXELS);
}

void shuffleArray(int* arrayToShuffle, const size_t arraySize) {
  for (size_t i = arraySize - 1; i > 0; --i) {
    // Pick a random index from 0 to i
    size_t r = random(0, i + 1);

    // Swap the elements at positions i and r
    int tempSwap = arrayToShuffle[i];
    arrayToShuffle[i] = arrayToShuffle[r];
    arrayToShuffle[r] = tempSwap;
  }
}


//================ New Function ====


What benefit are you gaining by making CRGBSet subsets of the CRGB rawleds[NUM_LEDS] array?

To do things like

        if (delayByStrip)
          FastLED.delay(wait);

which has some timed effect the sets.

I can't visualize what is happening, and I've never had to use FastLED sets.

I suppose some would find it easier than just writing the code to manage subsets.

a7

I like the idea to be able to address one strip at a time.

What do you mean "one strip at a time". There's only one strip that you're subdividing into logical strips. My question was why benefit do you get from that?

The purpose of the CRGBSet class is to handle index manipulation to allow treating a single LED string as multiple logical substrings each with a base index of 0. For example your CRGBSet led2 would be indexed as led2[0] … led2[4]. The CRGBSet class would then convert that to indices 9 – 13 of the physical strip.

But you’re not doing that at all. First off, this isn’t doing what you think:
struct CRGB* ledarray[] = { leds1, leds2, leds3, leds4 };

Looking in “pixelset.h”, you’ll see:

    /// Return a pointer to the first element in this set
    inline operator PIXEL_TYPE* () const { return leds; }

So, your ledarray[] simply contains 4 identical pointers to the same CRGB rawleds[NUM_LEDS].

So, you’re not actually using the CRGBSet objects at all!!! You’re just doing absolute indexing into CRGB rawleds[NUM_LEDS]! That’s the reason for you had to ask your original question about how to find if a given pixel is inside a given CRGBSet. If the CRGBSet objects were used properly, you’d never have to ask that question because you’d use zero-based indexing for each one.

Also, there's no need for this:

A proper array of CRGBSet objects would be created like this:

#include "FastLED.h"
constexpr size_t numLeds {30};

CRGB rawleds[numLeds];

CRGBSet setArray[] = {
  {rawleds, 0, 6},
  {rawleds, 9, 13},
  {rawleds, 18, 20},
  {rawleds, 27, 27}
};

I see. That makes a lot of sense. Thanks!