FastLed WS2812b layered effects. Possible?

New guy here learning the basics.

Is there a way to have a chasing led effect like fire or a comet happening over the built-in FastLed.h Confetti effect? A chasing effect blacks out after the tail, so without modification it erases the confetti effect after passing.

Thanks in advance

Randy

In post #58 I listed the code with some minor changes to make it look like the result I was after. Thank you to everyone who helped me on this, Grumpy_Mike, and especially gfvalvo for the code!

Yes you can but you will have to rewrite those effects so that they know about each other, otherwise they simply alternate what is shown.

For example you can separate two effects by say one using the Red LEDs and the other using say the Blue. Then every time you want to change a colour, you read what is there first and add that effects colour to it.

But maybe the problem is exactly what you mean by layered.

I think you got the gist of it, just a bit flabbergasted on how to go about this? The confetti effect uses all the leds in a blinking, pulsating way and I'll need to find out how to access the code in FastLed before anything else.

When using FastLED, just remember that every LED is represented in a array (of type CRGB). All that the effects do is fill the array with a pattern, like one frame of a movie, then do a FastLED.show();.
Follow that with a FastLED.delay(); so that you have time to see the "movie frame".
Now you write the LED data for the next frame and repeat.

If you want to merge two effects, just don't do the FastLed.show() between them. But, if the second effect writes CRGB::black to the array, it could mess up your desired output.

With the confetti effect lighting random LEDs and then dimming them, overlaying another effect would seem to require saving the current state of that effect. If you have sufficient memory, you could have an array for the confetti effect, another array for the 2nd effect, then combine the data from those arrays and place it in the actual LED buffer array. How exactly you combine the two effects would depend on how you want it to look, with confetti and comet do you want the bright pixels from confetti to show through the tail of the comet, or have the comet override the confetti until it passes, etc.

That would work. Something like

for (x=0,x<=numLeds,x++){
  LEDbuffer[x] = effect1Buffer[x] || effect2Buffer[x]
}
FastLED.show();

Then repeat for the next "frame".

You have used the logical OR to combine those two arrays, that will not work as it only returns a true or false. You need to use the bitwise operations, so the bitwise OR operation is | not ||.

You can also get a different effect if you combine the two effects with a bitwise AND operation & or the bitwise ExclusiveOR operation ^.

All these merge the two patterns in a different way, you will have to experiment to see what looks best.

Rather than use three buffers you can get away with just two, one for each effect and combine them into the buffer you want to display.

However that is no substitute for writing one effect that looks like two effects at once. That is hard thing to do because you have to think what it will look like.

These are not basic operations it is quite advanced stuff.

Mike, Steve, David, you guys are all right on target and have given me lots to think and play with, much appreciated.

Steve, I already wrote most of the code for the effect that I want to lay over the confetti. Can I add a video file here to show what I have? A couple of leds are streaking around the perimeter of a circle. Clockwise they show as blue and CC they are red. At this point they vary in speed and erase their previous position with CRGB::black.

As you pointed out, the black out will need to be replaced when merging the effects. Once they've shot about six or seven times, a "comet" will generate from the last position. This comet will have a couple of red leds as the head, then a yellow, then a light yellow with an orange tail that will not be blacked out. After the comet completes a full 360 degrees, it dissolves into the confetti effect. The confetti will run about 10 seconds and then everything repeats.

As it stands, the whole effect is not bad at all, at least it's very close to what I'm shooting for, but I'd really like to see what it would look like if the confetti persists throughout.

David, the part where the comet appears and then makes a 360 is the part that I'd like to be persistent. I want the orange tail to blot out the confetti only to have the confetti reappear after the 360 is complete.

Mike, right now the code is very compact, so the two buffers will determine the memory requirements. As I have not looked into buffers before, I have some homework ahead. I have 60 leds in the project creating a perimeter around a 10" subwoofer. Currently running this on an Uno. Once all is said and done, the Uno will be hooked up to a 4Ah 5V power supply. The duty cycle will be very short as the light show will only activate when the seat is pulled up revealing the speaker beneath.

Let me know how I can share a short video clip here so you guys can see what I have so far.

Thanks in bunches

R

This is still three buffers.

Good ideas for the different merges. You could still use the effects in FastLED. Fill array1 with the twinkle effect, fill array2 with the comet effect, then merge them into the display buffer.

Instead of doing a bitwise combining of two effects, you can also compare corresponding LEDs in each effect and display only the brighter of the two, display one only when the other is zeros (black), etc.

Like this?

2 Likes

With the comet effect, you could get away with keeping track of the head of the comet and generaring the led data every time instead of using a buffer.

No, buffer 1 effect 1, buffer 2, effect 2.
Then take each byte from buffer 1 and buffer 2, combine them and store it back in buffer 1.
Two buffers.

You still need a buffer to transfer data to the LEDs, you can not generate them in the fly. It is taking all the CPU cycles the processor has to transfer the data to the LEDs.

Yes you have. What do you think is where you put the data to display one effect in the first place, it is a buffer.

Post a link to the video use the chain link icon at the top of the reply box, and paste your URL into the box that pops up.

1 Like

That works. (Doh!)

Flash, that's about it. Now I just have to figure out how to combine two effects. Checked out your code and will need a little time to sort it out. Thank you

Did a search on FastLed/Confetti and found it in the GitHub FastLed library. So now I have a slightly altered (colors and speed change) Confetti Routine and the comet routine I wrote. Next I'll search for examples on combining the two animations.

Please keep the comments and suggestions coming as I am making good progress with your guy's help. I appreciate your patient explanations that put things in perspective for me.

R

Flash, I looked at your code and have to say that there are many elements of it that are beyond my current understanding of C. Off course I am willing to learn, but for now I need to finish this project and have to focus more on the basics of how to get two simple routines to play simultaneously. I am unfamiliar with code shortcuts or ways to write something with elegance and have to rely on brute force for now. To give you an example, here is my crude way of having my "comet" do a perimeter run:

  for(int whiteLed = 59; whiteLed > 0; whiteLed = whiteLed - 1) {
  leds[whiteLed] = CRGB::OrangeRed;
  T1 = whiteLed - 1;
  T2 = whiteLed - 2;
  T3 = whiteLed - 3;
  T4 = whiteLed - 4;
  leds[T1] = CRGB::Orange;
  leds[T2] = CRGB::OrangeRed;
  leds[T3] = CRGB::Red;
  leds[T4] = CRGB::Red;
  FastLED.show();
  delay(15);

I am sure there is a much simpler way of writing this, but I am still very new to this. This shows you my lack of sophistication, but I am slowly picking up things along my bumpy road. Will post a link to the video clip I made to show what I have so far.

R

Hope this works:

In this clip, it starts with the confetti effect and then transitions into the small bouncing routine followed by the "comet" doing a 360, back to the confetti.

1 Like

Not only that but it will write to array positions with a negative index, which should stomp over other data variables storage space and cause all sorts of strange behaviour.
The only reason what this could work is if the code in the FastLED library checks for negative values and corrects them to be zero.

Don’t try that with a normal array, you will not get away with it.

What hardware are you using in that video?