1+ // NeoPixelBuffer
2+ // This example will animate pixels using a bitmap stored on a SD card
3+ //
4+ //
5+ // This will demonstrate the use of the NeoBitmapFile object
6+ // NOTE: The images provided in the example directory should be copied to
7+ // the root of the SD card so the below code will find it.
8+ // NOTE: This sample and the included images were built for a 144 pixel strip so
9+ // running this with a smaller string may not look as interesting. Try providing
10+ // your own 24 bit bitmap for better results.
11+
12+ #include < NeoPixelBus.h>
13+ #include < NeoPixelAnimator.h>
14+ #include < SPI.h>
15+ #include < SD.h>
16+
17+ const int chipSelect = D8 ; // make sure to set this to your SD carder reader CS
18+
19+ // typedef NeoGrbFeature MyPixelColorFeature;
20+ typedef NeoGrbwFeature MyPixelColorFeature;
21+
22+ const uint16_t PixelCount = 144 ; // the sample images are meant for 144 pixels
23+ const uint16_t PixelPin = 2 ;
24+ const uint16_t AnimCount = 1 ; // we only need one
25+
26+ NeoPixelBus<MyPixelColorFeature, Neo800KbpsMethod> strip (PixelCount, PixelPin);
27+ NeoPixelAnimator animations (AnimCount); // NeoPixel animation management object
28+
29+ // our NeoBitmapFile will use the same color feature as NeoPixelBus and
30+ // we want it to use the SD File object
31+ NeoBitmapFile<MyPixelColorFeature, File> image;
32+
33+ uint16_t animState;
34+
35+ void LoopAnimUpdate (const AnimationParam& param)
36+ {
37+ // wait for this animation to complete,
38+ // we are using it as a timer of sorts
39+ if (param.state == AnimationState_Completed)
40+ {
41+ // done, time to restart this position tracking animation/timer
42+ animations.RestartAnimation (param.index );
43+
44+ // draw the complete row at animState to the complete strip
45+ image.Blt (strip, 0 , 0 , animState, image.Width ());
46+ animState = (animState + 1 ) % image.Height (); // increment and wrap
47+ }
48+ }
49+
50+ void setup () {
51+ Serial.begin (115200 );
52+ while (!Serial); // wait for serial attach
53+
54+ strip.Begin ();
55+ strip.Show ();
56+
57+ Serial.print (" Initializing SD card..." );
58+
59+ // see if the card is present and can be initialized:
60+ if (!SD .begin (chipSelect))
61+ {
62+ Serial.println (" Card failed, or not present" );
63+ // don't do anything more:
64+ return ;
65+ }
66+ Serial.println (" card initialized." );
67+
68+ // open the file
69+ File bitmapFile = SD .open (" strings.bmp" );
70+ if (!bitmapFile)
71+ {
72+ Serial.println (" File open fail, or not present" );
73+ // don't do anything more:
74+ return ;
75+ }
76+
77+ // initialize the image with the file
78+ if (!image.Begin (bitmapFile))
79+ {
80+ Serial.println (" File format fail, not a supported bitmap" );
81+ // don't do anything more:
82+ return ;
83+ }
84+
85+ animState = 0 ;
86+ // we use the index 0 animation to time how often we rotate all the pixels
87+ animations.StartAnimation (0 , 30 , LoopAnimUpdate);
88+ }
89+
90+ void loop () {
91+ // this is all that is needed to keep it running
92+ // and avoiding using delay() is always a good thing for
93+ // any timing related routines
94+ animations.UpdateAnimations ();
95+ strip.Show ();
96+ }
0 commit comments