Files

65 lines
2.0 KiB
Arduino
Raw Permalink Normal View History

2024-04-15 13:23:25 -07:00
// NeoPixelSpriteSheet
// This example will use a NeoVerticalSpriteSheet to animate a
// moving Cylon Red Eye back and forth across the
2016-04-16 12:52:21 -07:00
// the full collection of pixels on the strip.
//
2024-04-15 13:23:25 -07:00
2016-04-16 12:52:21 -07:00
#include <NeoPixelBus.h>
#include <NeoPixelAnimator.h>
2024-04-15 13:23:25 -07:00
// The actual image is contained in the data structure in the CylonRgb.h file
#include "CylonRgb.h"
2016-04-16 12:52:21 -07:00
2024-04-15 13:23:25 -07:00
const uint16_t PixelCount = myImageWidth; // the sample images are meant for 16 pixels, so we use the same for pixelcount
const uint16_t PixelPin = 2; // for esp8266 the pin is ignored in most methods
2016-04-16 12:52:21 -07:00
const uint16_t AnimCount = 1; // we only need one
2024-04-15 13:23:25 -07:00
NeoPixelBus<NeoGrbFeature, NeoWs2812xMethod> strip(PixelCount, PixelPin);
2016-04-16 12:52:21 -07:00
NeoPixelAnimator animations(AnimCount); // NeoPixel animation management object
// sprite sheet stored in progmem using the same pixel feature as the NeoPixelBus
2024-04-15 13:23:25 -07:00
NeoVerticalSpriteSheet_P<RgbColor> spriteSheet(
2024-04-12 22:58:44 -07:00
myImageWidth, // image width and sprite width since its vertical sprite sheet
myImageHeight, // image height
2024-04-15 13:23:25 -07:00
1, // sprite is only one pixel high in this example
2024-04-12 22:58:44 -07:00
myImage);
2016-04-16 12:52:21 -07:00
2024-04-15 13:23:25 -07:00
// animation state
2016-04-16 12:52:21 -07:00
uint16_t indexSprite;
void LoopAnimUpdate(const AnimationParam& param)
{
// wait for this animation to complete,
2024-04-15 13:23:25 -07:00
// we are using it as a timer
2016-04-16 12:52:21 -07:00
if (param.state == AnimationState_Completed)
{
// done, time to restart this position tracking animation/timer
animations.RestartAnimation(param.index);
// draw the next frame in the sprite
spriteSheet.Blt(strip, 0, indexSprite);
indexSprite = (indexSprite + 1) % myImageHeight; // increment and wrap
}
}
void setup()
{
strip.Begin();
strip.Show();
indexSprite = 0;
// we use the index 0 animation to time how often we rotate all the pixels
animations.StartAnimation(0, 60, LoopAnimUpdate);
}
void loop()
{
// this is all that is needed to keep it running
// and avoiding using delay() is always a good thing for
2024-04-15 13:23:25 -07:00
// any timing related solutions
2016-04-16 12:52:21 -07:00
animations.UpdateAnimations();
strip.Show();
}