-
I kindly ask a hint about how you would approach this request. My approach is:
I don't think I can avoid N animations (one per LED) since I need different states for each one in order to have N independent animations. Is my guess right? Is there a more recommended approach? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
You really should avoid delay() in all modern Arduino projects except for simple tests. It blocks other code from running far too often. Either use a task library (esp is RTOS and supports tasks natively) or use a micros() polling pattern. If you look in the NeoPixelAnimator.cpp for NeoPixelAnimator::UpdateAnimations(), you can see that it uses this pattern. You could use a single channel to do it, tracking all the state BUT this is what the animation manager already does so its not really going to save you anything. Using an animation channel per "twinkle" (this sort of animation you describe) is the normal approach. Generally, you would write a manager that tracks a set of available channels that it can use and their lifetime (is a single twinkle still animating or done so it can be reused). The manager would decide on when to create a twinkle, select an available channel from its set, and start the animation. The manager would be called in setup like "twinkleMan.update()", and internally use the millis() progress pattern instead of delay(). The twinkle animation callback could be written either to handle both fade in a fade out, or you could have two, one for fade in, that when complete uses the same channel to start another animation for fade out; where when the fade out completes, it releases the channel to be reused by the manager. This would give you the flexibility to have different timing to fade in and fade out. |
Beta Was this translation helpful? Give feedback.
-
Thanks for you hints! I'm not sure I understood them completely. I tried to write the following code. It works, but I cannot change the duration of each phase since the
Is there a way to change the I can do that, but I wonder if I can do this without using an external FSM. |
Beta Was this translation helpful? Give feedback.
-
I think I solved adding:
before restarting the animation. |
Beta Was this translation helpful? Give feedback.
I think I solved adding:
before restarting the animation.