25 #ifndef ACE_SEGMENT_PULSE_STYLER_H 26 #define ACE_SEGMENT_PULSE_STYLER_H 35 PulseStyler(uint8_t framesPerSecond, uint16_t durationMillis):
36 mFramesPerPulse((uint32_t) framesPerSecond * durationMillis / 1000),
37 mFramesPerPulseInverse((uint32_t) 65536 * 1000
38 / framesPerSecond / durationMillis)
42 uint16_t middleOfPulse = mFramesPerPulse / 2;
45 if (mCurrentFrame < middleOfPulse) {
46 fraction = (uint32_t) mFramesPerPulseInverse * mCurrentFrame / (256/2);
47 }
else if (mCurrentFrame < mFramesPerPulse) {
48 uint16_t reverse = (mFramesPerPulse - mCurrentFrame - 1);
49 fraction = (uint32_t) mFramesPerPulseInverse * reverse / (256/2);
53 if (fraction > 255) fraction = 255;
55 mPulseFraction = fraction;
59 virtual void apply(uint8_t* pattern, uint8_t* brightness)
override {
60 *brightness = ((uint16_t) mPulseFraction * (*brightness)) / 256;
66 const uint16_t mFramesPerPulse;
67 const uint16_t mFramesPerPulseInverse;
68 uint16_t mCurrentFrame = 0;
69 uint8_t mPulseFraction;
virtual bool requiresBrightness() override
Requires driver support for brightness control if true.
virtual void calcForFrame() override
Called once per frame to update the internal variables of the object.
Interface for classes which apply a style to the given bit pattern and brightness.
static void incrementMod(T &i, T m)
Increment i modulo m, avoiding expensive % operator on some 8-bit processors like AVR...
virtual void apply(uint8_t *pattern, uint8_t *brightness) override
Changes updates the brightness for current frame.