NeoPixelBufferCylon.ino 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // NeoPixelBufferCylon
  2. // This example will move a Cylon Red Eye back and forth across the
  3. // the full collection of pixels on the strip.
  4. //
  5. // This will demonstrate the use of the NeoVerticalSpriteSheet
  6. //
  7. #include <NeoPixelBus.h>
  8. #include <NeoPixelAnimator.h>
  9. // The actual image is contained in the data structure in one of the Cylon*.h files
  10. // You will need to use the one that has the same color feature as your NeoPixelBus
  11. // There are two provided, but you can create your own easily enough using
  12. // free versions of Paint.Net and the plugin
  13. #include "CylonGrb.h"
  14. typedef NeoGrbFeature MyPixelColorFeature;
  15. // #include "CylonGrbw.h"
  16. // typedef NeoGrbwFeature MyPixelColorFeature;
  17. const uint16_t PixelCount = 16; // the sample images are meant for 16 pixels
  18. const uint16_t PixelPin = 2;
  19. const uint16_t AnimCount = 1; // we only need one
  20. NeoPixelBus<MyPixelColorFeature, Neo800KbpsMethod> strip(PixelCount, PixelPin);
  21. // for esp8266 omit the pin
  22. //NeoPixelBus<MyPixelColorFeature, Neo800KbpsMethod> strip(PixelCount);
  23. NeoPixelAnimator animations(AnimCount); // NeoPixel animation management object
  24. // sprite sheet stored in progmem using the same pixel feature as the NeoPixelBus
  25. NeoVerticalSpriteSheet<NeoBufferProgmemMethod<MyPixelColorFeature>> spriteSheet(
  26. myImageWidth, // image width and sprite width since its vertical sprite sheet
  27. myImageHeight, // image height
  28. 1, // sprite is only one pixel high
  29. myImage);
  30. uint16_t indexSprite;
  31. void LoopAnimUpdate(const AnimationParam& param)
  32. {
  33. // wait for this animation to complete,
  34. // we are using it as a timer of sorts
  35. if (param.state == AnimationState_Completed)
  36. {
  37. // done, time to restart this position tracking animation/timer
  38. animations.RestartAnimation(param.index);
  39. // draw the next frame in the sprite
  40. spriteSheet.Blt(strip, 0, indexSprite);
  41. indexSprite = (indexSprite + 1) % myImageHeight; // increment and wrap
  42. }
  43. }
  44. void setup()
  45. {
  46. strip.Begin();
  47. strip.Show();
  48. indexSprite = 0;
  49. // we use the index 0 animation to time how often we rotate all the pixels
  50. animations.StartAnimation(0, 60, LoopAnimUpdate);
  51. }
  52. void loop()
  53. {
  54. // this is all that is needed to keep it running
  55. // and avoiding using delay() is always a good thing for
  56. // any timing related routines
  57. animations.UpdateAnimations();
  58. strip.Show();
  59. }