forked from Makuna/NeoPixelBus
A Few Fixes
Removed debug serial output Fix bug in animator where it would stop processing animations too early Added NeoGrbwFeature for common RGBW strips Cleaned up a sample that misbehaves if you change the pixel count
This commit is contained in:
@@ -17,12 +17,14 @@
|
||||
|
||||
const uint16_t PixelCount = 16; // make sure to set this to the number of pixels in your strip
|
||||
const uint16_t PixelPin = 2; // make sure to set this to the correct pin, ignored for Esp8266
|
||||
const uint16_t AnimCount = 8; // we only need about 8 animations, one to track movement, and the rest to actually animate
|
||||
const uint16_t AnimCount = PixelCount / 5 * 2 + 1; // we only need enough animations for the tail and one extra
|
||||
|
||||
const uint16_t PixelFadeDuration = 400; // half a second
|
||||
const uint16_t PixelFadeDuration = 300; // third of a second
|
||||
// one second divide by the number of pixels = loop once a second
|
||||
const uint16_t NextPixelMoveDuration = 1000 / PixelCount; // how fast we move through the pixels
|
||||
|
||||
NeoGamma<NeoGammaTableMethod> colorGamma; // for any fade animations, best to correct gamma
|
||||
|
||||
NeoPixelBus<NeoGrbFeature, Neo800KbpsMethod> strip(PixelCount, PixelPin);
|
||||
// For Esp8266, the Pin is ignored and it uses GPIO3.
|
||||
// There are other Esp8266 alternative methods that provide more pin options, but also have
|
||||
@@ -78,7 +80,8 @@ void FadeOutAnimUpdate(const AnimationParam& param)
|
||||
animationState[param.index].EndingColor,
|
||||
param.progress);
|
||||
// apply the color to the strip
|
||||
strip.SetPixelColor(animationState[param.index].IndexPixel, updatedColor);
|
||||
strip.SetPixelColor(animationState[param.index].IndexPixel,
|
||||
colorGamma.Correct(updatedColor));
|
||||
}
|
||||
|
||||
void LoopAnimUpdate(const AnimationParam& param)
|
||||
@@ -93,7 +96,7 @@ void LoopAnimUpdate(const AnimationParam& param)
|
||||
// pick the next pixel inline to start animating
|
||||
//
|
||||
frontPixel = (frontPixel + 1) % PixelCount; // increment and wrap
|
||||
if (frontPixel == 1)
|
||||
if (frontPixel == 0)
|
||||
{
|
||||
// we looped, lets pick a new front color
|
||||
frontColor = HslColor(random(360) / 360.0f, 1.0f, 0.25f);
|
||||
@@ -103,7 +106,7 @@ void LoopAnimUpdate(const AnimationParam& param)
|
||||
// do we have an animation available to use to animate the next front pixel?
|
||||
// if you see skipping, then either you are going to fast or need to increase
|
||||
// the number of animation channels
|
||||
if (animations.NextAvailableAnimation(&indexAnim, 0))
|
||||
if (animations.NextAvailableAnimation(&indexAnim, 1))
|
||||
{
|
||||
animationState[indexAnim].StartingColor = frontColor;
|
||||
animationState[indexAnim].EndingColor = RgbColor(0, 0, 0);
|
||||
|
@@ -1,5 +1,5 @@
|
||||
name=NeoPixelBus by Makuna
|
||||
version=2.0.7
|
||||
version=2.0.8
|
||||
author=Michael C. Miller (makuna@live.com)
|
||||
maintainer=Michael C. Miller (makuna@live.com)
|
||||
sentence=A library that makes controlling NeoPixels (WS2811, WS2812 & SK6812) easy.
|
||||
|
@@ -55,7 +55,7 @@ public:
|
||||
class NeoGrbFeature : public Neo3Elements
|
||||
{
|
||||
public:
|
||||
static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, Neo3Elements::ColorObject color)
|
||||
static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color)
|
||||
{
|
||||
uint8_t* p = getPixelAddress(pPixels, indexPixel);
|
||||
|
||||
@@ -64,9 +64,9 @@ public:
|
||||
*p = color.B;
|
||||
}
|
||||
|
||||
static Neo3Elements::ColorObject retrievePixelColor(uint8_t* pPixels, uint16_t indexPixel)
|
||||
static ColorObject retrievePixelColor(uint8_t* pPixels, uint16_t indexPixel)
|
||||
{
|
||||
Neo3Elements::ColorObject color;
|
||||
ColorObject color;
|
||||
uint8_t* p = getPixelAddress(pPixels, indexPixel);
|
||||
|
||||
color.G = *p++;
|
||||
@@ -77,10 +77,38 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
class NeoGrbwFeature : public Neo4Elements
|
||||
{
|
||||
public:
|
||||
static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color)
|
||||
{
|
||||
uint8_t* p = getPixelAddress(pPixels, indexPixel);
|
||||
|
||||
*p++ = color.G;
|
||||
*p++ = color.R;
|
||||
*p++ = color.B;
|
||||
*p = color.W;
|
||||
}
|
||||
|
||||
static ColorObject retrievePixelColor(uint8_t* pPixels, uint16_t indexPixel)
|
||||
{
|
||||
ColorObject color;
|
||||
uint8_t* p = getPixelAddress(pPixels, indexPixel);
|
||||
|
||||
color.G = *p++;
|
||||
color.R = *p++;
|
||||
color.B = *p++;
|
||||
color.W = *p;
|
||||
|
||||
|
||||
return color;
|
||||
}
|
||||
};
|
||||
|
||||
class NeoRgbwFeature : public Neo4Elements
|
||||
{
|
||||
public:
|
||||
static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, Neo4Elements::ColorObject color)
|
||||
static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color)
|
||||
{
|
||||
uint8_t* p = getPixelAddress(pPixels, indexPixel);
|
||||
|
||||
@@ -90,9 +118,9 @@ public:
|
||||
*p = color.W;
|
||||
}
|
||||
|
||||
static Neo4Elements::ColorObject retrievePixelColor(uint8_t* pPixels, uint16_t indexPixel)
|
||||
static ColorObject retrievePixelColor(uint8_t* pPixels, uint16_t indexPixel)
|
||||
{
|
||||
Neo4Elements::ColorObject color;
|
||||
ColorObject color;
|
||||
uint8_t* p = getPixelAddress(pPixels, indexPixel);
|
||||
|
||||
color.R = *p++;
|
||||
@@ -107,7 +135,7 @@ public:
|
||||
class NeoRgbFeature : public Neo3Elements
|
||||
{
|
||||
public:
|
||||
static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, Neo3Elements::ColorObject color)
|
||||
static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color)
|
||||
{
|
||||
uint8_t* p = getPixelAddress(pPixels, indexPixel);
|
||||
|
||||
@@ -116,9 +144,9 @@ public:
|
||||
*p = color.B;
|
||||
}
|
||||
|
||||
static Neo3Elements::ColorObject retrievePixelColor(uint8_t* pPixels, uint16_t indexPixel)
|
||||
static ColorObject retrievePixelColor(uint8_t* pPixels, uint16_t indexPixel)
|
||||
{
|
||||
Neo3Elements::ColorObject color;
|
||||
ColorObject color;
|
||||
uint8_t* p = getPixelAddress(pPixels, indexPixel);
|
||||
|
||||
color.R = *p++;
|
||||
@@ -132,7 +160,7 @@ public:
|
||||
class NeoBrgFeature : public Neo3Elements
|
||||
{
|
||||
public:
|
||||
static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, Neo3Elements::ColorObject color)
|
||||
static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color)
|
||||
{
|
||||
uint8_t* p = getPixelAddress(pPixels, indexPixel);
|
||||
|
||||
@@ -141,9 +169,9 @@ public:
|
||||
*p = color.G;
|
||||
}
|
||||
|
||||
static Neo3Elements::ColorObject retrievePixelColor(uint8_t* pPixels, uint16_t indexPixel)
|
||||
static ColorObject retrievePixelColor(uint8_t* pPixels, uint16_t indexPixel)
|
||||
{
|
||||
Neo3Elements::ColorObject color;
|
||||
ColorObject color;
|
||||
uint8_t* p = getPixelAddress(pPixels, indexPixel);
|
||||
|
||||
color.B = *p++;
|
||||
|
@@ -150,14 +150,6 @@ public:
|
||||
_i2sBufDesc[indexDesc].unused = 0;
|
||||
_i2sBufDesc[indexDesc].next_link_ptr = (uint32_t)&(_i2sBufDesc[indexDesc + 1]);
|
||||
|
||||
Serial.print("block #");
|
||||
Serial.print(indexDesc);
|
||||
Serial.print(" 0x");
|
||||
Serial.print(_i2sBufDesc[indexDesc].buf_ptr, HEX);
|
||||
Serial.print(" (");
|
||||
Serial.print(_i2sBufDesc[indexDesc].blocksize);
|
||||
Serial.println(")");
|
||||
|
||||
is2Buffer += blockSize;
|
||||
is2BufferSize -= blockSize;
|
||||
}
|
||||
|
@@ -117,12 +117,11 @@ void NeoPixelAnimator::UpdateAnimations()
|
||||
|
||||
if (delta >= _timeScale)
|
||||
{
|
||||
uint16_t countAnimations = _activeAnimations;
|
||||
AnimationContext* pAnim;
|
||||
|
||||
delta /= _timeScale; // scale delta into animation time
|
||||
|
||||
for (uint16_t iAnim = 0; iAnim < _countAnimations && countAnimations > 0; iAnim++)
|
||||
for (uint16_t iAnim = 0; iAnim < _countAnimations; iAnim++)
|
||||
{
|
||||
pAnim = &_animations[iAnim];
|
||||
AnimUpdateCallback fnUpdate = pAnim->_fnCallback;
|
||||
@@ -138,8 +137,6 @@ void NeoPixelAnimator::UpdateAnimations()
|
||||
fnUpdate(param);
|
||||
|
||||
pAnim->_remaining -= delta;
|
||||
|
||||
countAnimations--;
|
||||
}
|
||||
else if (pAnim->_remaining > 0)
|
||||
{
|
||||
@@ -150,8 +147,6 @@ void NeoPixelAnimator::UpdateAnimations()
|
||||
pAnim->StopAnimation();
|
||||
|
||||
fnUpdate(param);
|
||||
|
||||
countAnimations--;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user