# Reading elements in crgb array

**URL:** <https://forum.arduino.cc/t/reading-elements-in-crgb-array/1422767>\
**Category:** Programming\
**Created:** [December 31, 2025, 5:27pm UTC](https://forum.arduino.cc/t/reading-elements-in-crgb-array/1422767 "2025-12-31T17:27:32Z")\
**Posts on this page:** 9\
**Page:** 2

<div class="post-metadata">

**Author:** ![gfvalvo](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/gfvalvo/32/1013044_2.png) [@gfvalvo](https://forum.arduino.cc/u/gfvalvo)\
**Post date:** [January 5, 2026, 10:53pm UTC](https://forum.arduino.cc/t/reading-elements-in-crgb-array/1422767/21 "2026-01-05T22:53:30Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ski113](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ski113/32/1253383_2.png) [@ski113](https://forum.arduino.cc/u/ski113)\
**Post date:** [January 6, 2026, 10:08pm UTC](https://forum.arduino.cc/t/reading-elements-in-crgb-array/1422767/22 "2026-01-06T22:08:20Z")

</div>

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.

```arduino
// 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 ====

```

---

<div class="post-metadata">

**Author:** ![gfvalvo](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/gfvalvo/32/1013044_2.png) [@gfvalvo](https://forum.arduino.cc/u/gfvalvo)\
**Post date:** [January 6, 2026, 11:43pm UTC](https://forum.arduino.cc/t/reading-elements-in-crgb-array/1422767/23 "2026-01-06T23:43:18Z")

</div>

> [@ski113](#):
>
> My updated code is attached

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

---

<div class="post-metadata">

**Author:** ![alto777](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/alto777/32/317385_2.png) [@alto777](https://forum.arduino.cc/u/alto777)\
**Post date:** [January 7, 2026, 2:15am UTC](https://forum.arduino.cc/t/reading-elements-in-crgb-array/1422767/24 "2026-01-07T02:15:50Z")

</div>

To do things like

```arduino
        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

---

<div class="post-metadata">

**Author:** ![ski113](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ski113/32/1253383_2.png) [@ski113](https://forum.arduino.cc/u/ski113)\
**Post date:** [January 7, 2026, 2:30am UTC](https://forum.arduino.cc/t/reading-elements-in-crgb-array/1422767/25 "2026-01-07T02:30:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![gfvalvo](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/gfvalvo/32/1013044_2.png) [@gfvalvo](https://forum.arduino.cc/u/gfvalvo)\
**Post date:** [January 7, 2026, 2:40am UTC](https://forum.arduino.cc/t/reading-elements-in-crgb-array/1422767/26 "2026-01-07T02:40:20Z")

</div>

> [@ski113](#):
>
> 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?

---

<div class="post-metadata">

**Author:** ![gfvalvo](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/gfvalvo/32/1013044_2.png) [@gfvalvo](https://forum.arduino.cc/u/gfvalvo)\
**Post date:** [January 7, 2026, 3:29am UTC](https://forum.arduino.cc/t/reading-elements-in-crgb-array/1422767/27 "2026-01-07T03:29:07Z")

</div>

> [@ski113](#):
>
> I like the idea to be able to address one strip at a time

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:

```arduino
    /// 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:

> [@ski113](#):
>
> `CRGBSet leds(rawleds, NUM_LEDS);`

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

```arduino
#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}
};

```

---

<div class="post-metadata">

**Author:** ![ski113](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ski113/32/1253383_2.png) [@ski113](https://forum.arduino.cc/u/ski113)\
**Post date:** [January 8, 2026, 7:19pm UTC](https://forum.arduino.cc/t/reading-elements-in-crgb-array/1422767/28 "2026-01-08T19:19:44Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [July 7, 2026, 7:19pm UTC](https://forum.arduino.cc/t/reading-elements-in-crgb-array/1422767/29 "2026-07-07T19:19:45Z")

</div>

Closed on July 7, 2026, 7:19pm UTC

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.

[Previous page](https://forum.arduino.cc/t/reading-elements-in-crgb-array/1422767.md?page=1)
