forked from Makuna/NeoPixelBus
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:
@@ -875,6 +875,24 @@ void NeoPixelBus::SetPixelColor(
|
|||||||
uint8_t b)
|
uint8_t b)
|
||||||
{
|
{
|
||||||
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
|
||||||
@@ -893,7 +911,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)
|
||||||
RgbColor NeoPixelBus::GetPixelColor(uint16_t n) const
|
RgbColor NeoPixelBus::GetPixelColor(uint16_t n) const
|
||||||
@@ -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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -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
|
||||||
|
Reference in New Issue
Block a user