Files
NeoPixelBus/examples/bitmaps/NeoPixelBitmap/NeoPixelBitmap.ino

95 lines
2.8 KiB
Arduino
Raw Normal View History

2016-04-23 14:40:01 -07:00
// NeoPixelBuffer
// This example will animate pixels using a bitmap stored on a SD card
//
//
// This will demonstrate the use of the NeoBitmapFile object
// NOTE: The images provided in the example directory should be copied to
// the root of the SD card so the below code will find it.
// NOTE: This sample and the included images were built for a 144 pixel strip so
// running this with a smaller string may not look as interesting. Try providing
// your own 24 bit bitmap for better results.
#include <NeoPixelBus.h>
#include <NeoPixelAnimator.h>
#include <SPI.h>
#include <SD.h>
2024-04-12 22:58:44 -07:00
const int chipSelect = 8; // make sure to set this to your SD carder reader CS
2016-04-23 14:40:01 -07:00
const uint16_t PixelCount = 144; // the sample images are meant for 144 pixels
2024-04-15 13:23:25 -07:00
const uint16_t PixelPin = 2; // for esp8266 the pin is ignored with most methods
2016-04-23 14:40:01 -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-23 14:40:01 -07:00
NeoPixelAnimator animations(AnimCount); // NeoPixel animation management object
2024-04-15 13:23:25 -07:00
// our NeoBitmapFile will use the RgbColor
NeoBitmapFile<RgbColor, File> image;
2016-04-23 14:40:01 -07:00
2024-04-15 13:23:25 -07:00
// animation state
2016-04-23 14:40:01 -07:00
uint16_t animState;
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-23 14:40:01 -07:00
if (param.state == AnimationState_Completed)
{
// done, time to restart this position tracking animation/timer
animations.RestartAnimation(param.index);
// draw the complete row at animState to the complete strip
image.Blt(strip, 0, 0, animState, image.Width());
animState = (animState + 1) % image.Height(); // increment and wrap
}
}
2024-04-15 13:23:25 -07:00
void setup()
{
2016-04-23 14:40:01 -07:00
Serial.begin(115200);
while (!Serial); // wait for serial attach
strip.Begin();
strip.Show();
Serial.print("Initializing SD card...");
// see if the card is present and can be initialized:
if (!SD.begin(chipSelect))
{
Serial.println("Card failed, or not present");
// don't do anything more:
return;
}
Serial.println("card initialized.");
// open the file
2024-04-12 22:58:44 -07:00
File bitmapFile = SD.open("strings.bmp");
2016-04-23 14:40:01 -07:00
if (!bitmapFile)
{
Serial.println("File open fail, or not present");
// don't do anything more:
return;
}
// initialize the image with the file
if (!image.Begin(bitmapFile))
{
Serial.println("File format fail, not a supported bitmap");
// don't do anything more:
return;
}
animState = 0;
// we use the index 0 animation to time how often we rotate all the pixels
animations.StartAnimation(0, 30, LoopAnimUpdate);
}
2024-04-15 13:23:25 -07:00
void loop()
{
2016-04-23 14:40:01 -07:00
// 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-23 14:40:01 -07:00
animations.UpdateAnimations();
strip.Show();
}