diff --git a/NeoPixelBus.cpp b/NeoPixelBus.cpp index f36d391..e4f098d 100644 --- a/NeoPixelBus.cpp +++ b/NeoPixelBus.cpp @@ -876,25 +876,42 @@ void NeoPixelBus::SetPixelColor( { if (n < _countPixels) { - uint8_t *p = &_pixels[n * 3]; -#ifdef NEO_RGB - if ((_flagsPixels & NEO_COLMASK) == NEO_GRB) + // clear any animation + if (_animations[n].time != 0) { -#endif - *p++ = g; - *p++ = r; -#ifdef NEO_RGB - } - else - { - *p++ = r; - *p++ = g; + _activeAnimations--; + _animations[n].time = 0; + _animations[n].remaining = 0; } -#endif - *p = b; + UpdatePixelColor(n, r, g, b); } } +// Set pixel color from separate R,G,B components: +void NeoPixelBus::UpdatePixelColor( + uint16_t n, + uint8_t r, + uint8_t g, + uint8_t b) +{ + uint8_t *p = &_pixels[n * 3]; +#ifdef NEO_RGB + if ((_flagsPixels & NEO_COLMASK) == NEO_GRB) + { +#endif + *p++ = g; + *p++ = r; +#ifdef NEO_RGB + } + else + { + *p++ = r; + *p++ = g; + } +#endif + *p = b; +} + // Query color from previously-set pixel (returns packed 32-bit RGB value) RgbColor NeoPixelBus::GetPixelColor(uint16_t n) const { @@ -979,17 +996,14 @@ void NeoPixelBus::UpdateAnimations() pAnim->target, progress); - SetPixelColor(iAnim, color); + UpdatePixelColor(iAnim, color); countAnimations--; } else if (pAnim->remaining > 0) { + // specifically calling SetPixelColor so it will clear animation state SetPixelColor(iAnim, pAnim->target); - pAnim->remaining = 0; - pAnim->time = 0; countAnimations--; - _activeAnimations--; - Serial.print(iAnim); } } } diff --git a/NeoPixelBus.h b/NeoPixelBus.h index 2d018de..959e87a 100644 --- a/NeoPixelBus.h +++ b/NeoPixelBus.h @@ -80,6 +80,11 @@ public: private: void setPin(uint8_t p); + void UpdatePixelColor(uint16_t n, uint8_t r, uint8_t g, uint8_t b); + void UpdatePixelColor(uint16_t n, RgbColor c) + { + UpdatePixelColor(n, c.R, c.G, c.B); + }; const uint16_t _countPixels; // Number of RGB LEDs in strip const uint16_t _sizePixels; // Size of '_pixels' buffer below