No need for additional code or scanning. You already know which strips contain which CRGBSet subsets because it's your code that created the CRGBSet subsets in the first place.
If that's not what you're asking, then you need to ask for what you want more clearly.
You can just go through the array and check each LED to see if it matches the one you’re looking for. That way, you can figure out which strip contains a specific LED. Have you tried scanning the other arrays the same way to see if it works consistently?
You are clearly referencing a piece of code, hopefully within a complete, functional sketch. Fine. Please either provide that complete, functional sketch here(to learn how to paste code, see the How to get the best... message), or, provide a link to the website page where you found the code you're asking about.
Thank you.
leds1 (0, 6).fill_rainbow(0, 25); fills LED zero through six with rainbow effect.
Your instance of FastLED is leds Your instance of CRGBSet is leds1 which contains from LED 0 through LED 6.
Your instance of CRGBSet is leds1 which contains six LEDs starting from LED 0.
So I have an array of arrays and want to see if the led (element) is in the strip I am scanning.
My code (in progress) is below but the bottom line is I don't know how to get the led numbers in the strip. I am a professional C# programmer and feel embarrassed I can't figure this out.
boolean arrayContains(CRGB* arrayName, int element, int arraySize) {
//return true;
for (int i = 0; i < arraySize; i++) {
Serial.write(i);
Serial.write(element);
//Serial.write(arrayName[i]);
Serial.write("----------");
if ( arrayName[i]== element) {
return true; // Element found
}
}
return false; // Element not found after checking all elements
}
void fillTreeSolidHorizontal() {
uint8_t NumColors = sizeof(CRGBColorArray) / sizeof(CRGBColorArray[0]);
for (uint8_t colorIdx = 0; colorIdx < NumColors; colorIdx++) {
for (uint8_t lrow = 0; lrow < 8; lrow++) {
for (uint8_t x = 0; x < size_step_array; x++) {
if (arrayContains(ledarray[x], 19, rowleds[x])){
//ledarray[x][3] = CRGBColorArray[colorIdx];
ledarray[x][lrow] = CRGBColorArray[colorIdx];
//ledarray[x][1] = CRGBColorArray[colorIdx];
}
FastLED.show();
delay(700);
}
}
}
}
CRGBSet leds1(leds(0, 6));
CRGBSet leds2(leds(9, 13));
CRGBSet leds3(leds(18, 2));
CRGBSet leds4(leds(27, 27));
//CRGBSet leds5(leds(35, 35));
struct CRGB* ledarray[] = { leds1, leds2, leds3, leds4 };
I flagged your post for moderation, as dual accounts are not permitted, AFAIK - and I realize, this may be inadvertent, but it needs cleaning up, at minimum.
About your question, I'm unclear why you think each LED should have a "number" - are you thinking an addressable LED somehow has an address embedded within the library? Because they don't, their 'addressability' relates only to their connection order in the string.
IF that's not what you're asking, then perhaps you need to restate your problem in a different way.
Address/color the first element in each sub-array with a different color.
I am not a fan of that method you are using. It is too intricate for me, and I lose control of it/them. I prefer to have all my leds in a flat array, and write to sub-sets of that flat array.
Here is an example of using subsets...
int section[] = { 13, 3, 7, 6, 9, 4, 7 }; // LEDs in segments of the lightning bolt
You appear to have created a new account to reply to this topic. Please use your original account @ski113 . You are allowed one account on the forum, creating duplicate accounts can lead to suspension from the forum.
I'm sure you coukd write a loop over those and find a range that a given pixel number is in, or fail to find one becuase it isn't. Isn't part of any of the ranges.
Maintain or initialise start and lenth. I bet there's a C++ wizard who can improve this to mean you only had to write one description of the range(s) and the code woukd take care of the other uses the range needs to be put to.
it is not legit. leds1 , leds2 , etc., are CRGBSet objects, not CRGB* pointers, so you cannot put them into struct CRGB* ledarray[] . The types are incompatible.
And even if you fix that, the arrayContains function assumes it can compare arrayName[i] == element to check if a given LED number exists in the array. This does not work because CRGBSet does not store LED numbers; indexing (operator[]) returns a reference to a CRGB color, not the LED number. So arrayContains cannot determine whether a specific LED number is present.
The declaration of the CRGBSet objects is also nonsense. It's trying to call the leds array like a function (eg ... leds(0, 6)). The correct syntax would be: CRGBSet leds1(leds, 0, 6);
I don't know what the struct keyword is doing there either:
You can loop through the array using a simple for loop and compare each LED to the one you’re looking for. For example, if your array is leds1 and you want to check for targetLED, you iterate through the indices and check if leds1[i] == targetLED. If it matches, you know that the LED is in that strip. This works the same way for multiple arrays, loop through each one.