-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Don't repeat the animation after reaching the end of the segment? #2
Comments
Hi - I think the simplest way to do what you are looking for would be to override the onCycleEnd method:
class FirstLightFX : public FFXBase {
public:
FirstLightFX(uint16_t initSize) : FFXBase( initSize,/* interval */ 15UL,
/* min interval */ 15UL,
/* max interval */ 30UL ) {
getFXColor().setColorMode( FFXColor::FFXColorMode::singleCRGB );
getFXColor().setCRGB( CRGB::White );
}
virtual void initLeds( CRGB *bufLeds ) override {
fill_solid( bufLeds, numLeds, CRGB::Black );
}
virtual void onCycleEnd( CRGB *currFrame ) override {
endAnimation = true;
}
virtual void writeNextFrame( CRGB *bufLeds ) override {
Serial.print("CYCLE: ");
Serial.println(getCurrCycle());
Serial.print("PHASE: ");
Serial.println(getMovementPhase());
fadeToBlackBy( bufLeds, numLeds, 25 );
if(!endAnimation) {
bufLeds[getMovementPhase() - 1] = currColor.getCRGB();
}
// if (getMovementPhase() > numLeds) {
// endAnimation = true;
// }
}
};
Let me know if you have any issues and I can help you get the desired behavior. Best -
***@***.***
… On Apr 19, 2021, at 4:56 AM, Oscar ***@***.***> wrote:
Hello, your library is very user-friendly and allows you to do great things with less code.
I had one question:
I have divided the strip into 12 segments and I want to make the segment play the animation once, how can I achieve this?
My current code:
https://gist.github.com/OSDDQD/575b3270baeeceda3c9d058701cda1b7 <https://gist.github.com/OSDDQD/575b3270baeeceda3c9d058701cda1b7>
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub <#2>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AOZFQL4GSB3MBWXFN5Z6JMTTJP46FANCNFSM43FPRZSA>.
|
Thank you for such a quick response. is it possible to determine which segment has now completed the cycle in this method? Each segment differs only in the number of pixels |
Yes - Just move your variable to inside the effect class. That way it will only affect the segment in question - as follows:
class FirstLightFX : public FFXBase {
private:
bool endAnimation = false;
public:
void setEndAnimation( bool newValue ) { endAnimation = newValue; }
bool getEndAnimation() { return endAnimation; }
FirstLightFX(uint16_t initSize) : FFXBase( initSize,/* interval */ 15UL,
/* min interval */ 15UL,
/* max interval */ 30UL ) {
getFXColor().setColorMode( FFXColor::FFXColorMode::singleCRGB );
getFXColor().setCRGB( CRGB::White );
}
virtual void initLeds( CRGB *bufLeds ) override {
fill_solid( bufLeds, numLeds, CRGB::Black );
}
virtual void onCycleEnd( CRGB *currFrame ) override {
endAnimation = true;
}
virtual void writeNextFrame( CRGB *bufLeds ) override {
Serial.print("CYCLE: ");
Serial.println(getCurrCycle());
Serial.print("PHASE: ");
Serial.println(getMovementPhase());
fadeToBlackBy( bufLeds, numLeds, 25 );
if(!endAnimation) {
bufLeds[getMovementPhase() - 1] = currColor.getCRGB();
}
}
};
Note that if you want to check or reset the endAnimation on any individual segment, you need to cast that segment's FX object to your effect type, so you would use something like: (FirstLightFX)(seg->getFX())->setEndAnimation(false);
FWIW - For what you are looking to accomplish, it may make more sense to use the OverlayFX class, which is intended to only run through a single cycle. There’s not an example that does exactly the same thing, but the ZipOverlayFX class would be close. The advantage to doing this is that you can have another color or effect in the background, and the overlay effect is “run” over the top of this and then disposed when it completes. You would do something like this:
FFXOverlay *newOvl;
// do this for each segment, each time you want to run a “one-shot” animation -
newOvl = new ZipOverlayFX( seg->getLength(), 255, 1); // speed: 255, cycles: 1
newOvl -> setPalette( NamedPalettes::getInstance()[“white_wave_gp”];
newOvl -> setMovement( FFXBase::MovementType::MVT_FORWARD );
newOvl -> setAlpha(255); // opacity - 255 is max
seg->setOverlay(newOvl);
Geoff Moehrke
***@***.***
… On Apr 20, 2021, at 4:09 AM, Oscar ***@***.***> wrote:
Thank you for such a quick response. is it possible to determine which segment has now completed the cycle in this method? Each segment differs only in the number of pixels
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub <#2 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AOZFQL65WOILKA5NXY6WHPLTJVADHANCNFSM43FPRZSA>.
|
Perhaps it is worth making it a separate issue |
The findSegment() function takes a String reference as a parameter - I’m not sure how you are calling it, but if you’re using a constant, you should be able to just create an inline String by doing: ctrler->findSegment( String(MY_CONST) );
Geoff Moehrke
***@***.***
… On Apr 21, 2021, at 7:45 AM, Oscar ***@***.***> wrote:
Perhaps it is worth making it a separate issue
The findSegment function produces a compilation error:
error: no matching function for call to 'FFXController :: findSegment (const char [6])'
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub <#2 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AOZFQL7CRBECIFD6QVNTBJ3TJ3CHFANCNFSM43FPRZSA>.
|
I'm using #3 example for base, like that in setup section:
And this in loop section: I'm not using constants for segment names |
Ok: I'll have to add a method for findSegment that handles that, in the meantime - |
Thank you, using overlay is correct solution in my case |
Hello, your library is very user-friendly and allows you to do great things with less code.
I had one question:
I have divided the strip into 12 segments and I want to make the segment play the animation once, how can I achieve this?
My current code:
https://gist.github.com/OSDDQD/575b3270baeeceda3c9d058701cda1b7
The text was updated successfully, but these errors were encountered: