SetPixelColor clears Animation state

If there is an active animation for the pixel when SetPixelColor is
called, it will be stopped.
This commit is contained in:
Makuna
2014-10-13 10:25:46 -07:00
parent 5f484cf939
commit b06f90a0af
2 changed files with 38 additions and 19 deletions

View File

@@ -876,6 +876,24 @@ void NeoPixelBus::SetPixelColor(
{ {
if (n < _countPixels) if (n < _countPixels)
{ {
// clear any animation
if (_animations[n].time != 0)
{
_activeAnimations--;
_animations[n].time = 0;
_animations[n].remaining = 0;
}
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]; uint8_t *p = &_pixels[n * 3];
#ifdef NEO_RGB #ifdef NEO_RGB
if ((_flagsPixels & NEO_COLMASK) == NEO_GRB) if ((_flagsPixels & NEO_COLMASK) == NEO_GRB)
@@ -892,7 +910,6 @@ void NeoPixelBus::SetPixelColor(
} }
#endif #endif
*p = b; *p = b;
}
} }
// Query color from previously-set pixel (returns packed 32-bit RGB value) // Query color from previously-set pixel (returns packed 32-bit RGB value)
@@ -979,17 +996,14 @@ void NeoPixelBus::UpdateAnimations()
pAnim->target, pAnim->target,
progress); progress);
SetPixelColor(iAnim, color); UpdatePixelColor(iAnim, color);
countAnimations--; countAnimations--;
} }
else if (pAnim->remaining > 0) else if (pAnim->remaining > 0)
{ {
// specifically calling SetPixelColor so it will clear animation state
SetPixelColor(iAnim, pAnim->target); SetPixelColor(iAnim, pAnim->target);
pAnim->remaining = 0;
pAnim->time = 0;
countAnimations--; countAnimations--;
_activeAnimations--;
Serial.print(iAnim);
} }
} }
} }

View File

@@ -80,6 +80,11 @@ public:
private: private:
void setPin(uint8_t p); 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 _countPixels; // Number of RGB LEDs in strip
const uint16_t _sizePixels; // Size of '_pixels' buffer below const uint16_t _sizePixels; // Size of '_pixels' buffer below