Wouldn't it be nice to work on entire sets of leds at once?

Wouldn’t it be nice to work on entire sets of leds at once? People keep asking for it, and I think I found a way to do it that I’m happy enough with. Imagine if you could write:

leds(0,4) = CRGB::Red;

to set the first 5 leds to be red. Or what if you wanted to copy the contents of the first part of your led array to the second part?

leds(10,19) = leds(0,9);

why don’t we mirror it, instead?

leds(10,19) = -leds(0,9);

and let’s fade everything out the way we like to:

leds.fadeToBlackBy(32);

what about some math?

leds *= 2;

or let’s just do that on some of the leds

leds(5,9) *= 2;

let’s put a rainbow on our leds:

leds.fill_rainbow(hue++);

or, again, just on a subset of the leds:

leds(10,14).fill_rainbow(hue++);

Welcome to CRGBSet - https://github.com/FastLED/FastLED/wiki/RGBSet-Reference!

The heart of the CRGBSet is the ability to take a subset of leds, and a subset is defined as being the first led and the last led you want in the set. So:

leds(10,14) starts at led index 10 and ends at led index 14 and has 5 leds in it - 10,11,12,13,14. Of course, you can reverse that and say leds(14,10) - which still has five leds in it, but leds(14,10)[0] will be led 14 :slight_smile:

Once you have a set of leds, you can do all sorts of things to them. How do you get that first set of leds? Simple, you slightly tweak your led creation:

CRGBArray<NUM_LEDS> leds;

Now you have a CRGBSet that represents all your leds. You can then take subsets of it. leds(0,9) returns a subset of the first 10 leds in your set of leds - this subset is also a CRGBSet - which means you could, in theory, take a subset of that!

Want to duplicate the leds from the first half of your strip to the second half?

leds(NUM_LEDS/2, NUM_LEDS-1) = leds(0,NUM_LEDS/2-1);

What about mirroring? That’s easy, just reverse the ordering of one of the sets:

leds(NUM_LEDS/2, NUM_LEDS-1) = leds(NUM_LEDS/2-1, 0);

Pretty much everything you can do to a CRGB you can do to a CRGBSet. CRGBSet also has fill_rainbow, fill_gradient, nblend, etc… methods on it as well.

Still adding to this - now there’s support for C++11 ranged for loops (if you’re building in an environment that supports C++11) - for example to set pixels 8-10 to random colors:

for(CRGB & pixel : leds(8,10)) { pixel = CHSV(random8(), 255,255); }

Of course, you can do this over all your leds:

for(CRGB & pixel : leds) { pixel = fadeToBlackBy(40); }

(which is equivalent to leds.fadeToBlackBy(40);, but just wanted to show this stuff off)

This is VERY VERY alpha code. It probably has bugs, it is probably incomplete. It might set your house on fire. Use at your own risk.

And have fun!

[ETA: And now i’m going to be out for much of the rest of the night - split even odds on me responding to comments in the next half hour, code updates are right now. It’s like tossing a live grenade into the playroom just before stepping out for lunch :]

Oh boy.

Here I was hoping to get some sleep tonight…

Thanks for your hard work, Daniel. As always, great stuff!

Wow, this gives some interesting new options! :smiley:

OMG OMG OMG!! I feel this was literally made for me!!! It fits almost exactly what I need!! Thanks!

There are some elements of syntax I’m still going back and forth on. By making set ranges inclusive - it makes for some awkward code:

leds(NUM_LEDS-1, NUM_LEDS/2) = leds(0,NUM_LEDS/2 - 1);

However, you can say leds(0,5) to means LEDs 0,1,2,3,4,5 or you can say leds(5,0) to mean LEDs 5,4,3,2,1,0. If, however, it is not inclusive then things felt awkward in different ways. Eg leds(1,5) - would only be 4 LEDs if we excluded one side, and it’s some what understood. However leds(5,1) - would the first led be 5 or would it be 1? Having the range be inclusive of both sides removes that ambiguity.

I thought briefly about making it “first led, then count of LEDs in the set” - using negative numbers to account for a set going backwards. Again, there were elements about that I wasn’t overly thrilled with.

I’m still going back and forth on that side of things.

I feel like there’s a lot we’re going to be able to build on this model. Great conceptual step!

This is sensacional ¡
daniel. Could you point where is the additional code you have developed , thank you

It’s on the master branch here - http://fastled.io/code - there will be more changes coming to it as I work on expanding/refining it, but figured it was worth letting people play with it now :slight_smile:

Daniel, is it posible for you to change the library version, so the arduino lib manager detects it as e new release ?

it says :…
… Ensure you’ve changed version in your library.properties. Then tag your library once more and push the new tag, or create a new release with github “releases”. Our job will eventually fetch and publish your new release.

thankyou !

No, not yet, because the repo is going to be in a lot of flux over the next few days, once things stabilize, I’ll do that, but for now people should be getting this stuff by downloading it directly, not using the library manager. (Mostly because I don’t want people getting this accidentally - especially if there’s things in there that destabilize the code a bit)

thank you i understand , i did as you mentioned .

daniel, i know it is early to try , but the new concept is so powerful that i couldn’t resist .
i have tried to convert the code to the new ledARRAY, as i was already “virtualizing” or mapping my leads to independently manage different segments that are part of the same strip, and also have 3 strips running in parallel .

the code works to certain point , but does wired things on some parts ,
then by adding a simple definition , it gives me this error at compile time

inline CPixelView(const CPixelView & other) : leds(other.leds), len(other.len), dir(other.dir), end_pos(other.end_pos) {}
^
no match for call to ‘(CRGBArray<50>) (int&)’

as everything looks fine , i don’t know what else to test ,

**
on the definitions i have changed

// CRGBArray<NUM_LEDS_PER_STRIP> leds[NUM_ARMS] ; //

for
CRGB leds[NUM_ARMS][NUM_LEDS_PER_STRIP]; //

any recommendations ,
THANKYOU

Hmmm - so - I have only tested

CRGBArray<NUM_LEDS> leds;

I haven’t tried an array of CRGBArray objects yet - i’ll have to add that to the list of things to test and work on.

you have my vote on your good work, the concept is so good , it will let us get rid of most of the intermediate mapping arrays , and make more complex effect very simple .

i see , what you are doing on the code, but that type of coding is not on my skills yet, so will continue to study your pixelset.h .

It is a much simpler version of something that I use in my private pattern library/code. I have all sorts of containers. I have containers that do n-way mapping (so you have one set of CRGB objects that you write to, that will map out to multiple other sets of less), I have containers that are virtual containers that can move (fractionally, even!) along another set of leds, which is nice for layering effects, and I have a few others as well. However, using them has a lot of quirks that, while i’m comfortable with them, I’m not terribly comfortable with giving to other people to use/supporting. Some of the stuff that i’m doing with PixelSets though is going to lay the ground work for being able to do bigger things like that in the future.

@Daniel_Garcia you are the Master! Thx of making my favorite library more and more god like :wink:
This features are really awesome!

Yeah. Great job! Thanks Daniel. I have a request if i can. Do you think it is possible to have a sentence like leds(10-14, 17,20, 25-30) where 10-14 is a group and 17,20 (separate by commas or something else) are single leds?

No - in part because of just the way the language syntax works - the compiler will see “10-14” and immediately treat it as an arithmetic so what you typed would turn into leds(-4,17,20,-5). I will probably eventually set up something that can be an arbitrary mapping - though doing that without introducing a lot of unnecessary overhead will be tricky. (And given that my focus is still on, at some level, performance - introducing something that allows for more compact code while making things slower is less likely to be done. If i’m hiding complexity - sure, though in this case it’d actually be an introduction of more complexity).

Once I get more expressive mapping in there, you’ll likely be able to set up something like what you describe - but it’s going to be a while before that happens.

Just found this in the references. Great work, I won’t use it just yet for my production code until i know its good to go but I will probably play with it in my personal bench work to see how much easier making patterns will be. thanks again for the great coding effort. you are the man!

@Daniel_Garcia i had some time to play with this last night. Quite simply the cherry on the cake.

I take my hat off to you sir.

Right, i’m off to de nest the 30 for loops i have!