buffer examples compile

This commit is contained in:
Michael Miller committed 2024-04-12 22:58:44 -07:00
1 parent 50bfc2f44e
commit c81721e595
13 files changed
+108 -268

No files matched your search

@@ -14,7 +14,7 @@
#include <SPI.h>
#include <SD.h>
const int chipSelect = D8; // make sure to set this to your SD carder reader CS
const int chipSelect = 8; // make sure to set this to your SD carder reader CS
//typedef NeoGrbFeature MyPixelColorFeature;
typedef NeoGrbwFeature MyPixelColorFeature;
@@ -30,7 +30,7 @@ NeoPixelAnimator animations(AnimCount); // NeoPixel animation management object
// our NeoBitmapFile will use the same color feature as NeoPixelBus and
// we want it to use the SD File object
NeoBitmapFile<MyPixelColorFeature, File> image;
NeoBitmapFile<MyPixelColorFeature::ColorObject, File> image;
uint16_t animState;
@@ -68,7 +68,7 @@ void setup() {
Serial.println("card initialized.");
// open the file
File bitmapFile = SD.open("strings.bmp");
File bitmapFile = SD.open("strings.bmp");
if (!bitmapFile)
{
Serial.println("File open fail, or not present");
@@ -19,7 +19,7 @@ typedef NeoGrbFeature MyPixelColorFeature;
// typedef NeoGrbwFeature MyPixelColorFeature;
const uint16_t PixelCount = 16; // the sample images are meant for 16 pixels
const uint16_t PixelPin = 2;
const uint16_t PixelPin = 2;
const uint16_t AnimCount = 1; // we only need one
NeoPixelBus<MyPixelColorFeature, NeoWs2812xMethod> strip(PixelCount, PixelPin);
@@ -28,11 +28,11 @@ NeoPixelBus<MyPixelColorFeature, NeoWs2812xMethod> strip(PixelCount, PixelPin);
NeoPixelAnimator animations(AnimCount); // NeoPixel animation management object
// sprite sheet stored in progmem using the same pixel feature as the NeoPixelBus
NeoVerticalSpriteSheet<NeoBufferProgmemMethod<MyPixelColorFeature>> spriteSheet(
myImageWidth, // image width and sprite width since its vertical sprite sheet
myImageHeight, // image height
1, // sprite is only one pixel high
myImage);
NeoVerticalSpriteSheet<NeoBufferProgmemMethod<MyPixelColorFeature::ColorObject>> spriteSheet(
myImageWidth, // image width and sprite width since its vertical sprite sheet
myImageHeight, // image height
1, // sprite is only one pixel high
myImage);
uint16_t indexSprite;
@@ -71,4 +71,3 @@ void loop()
animations.UpdateAnimations();
strip.Show();
}
@@ -1,7 +1,7 @@
// NeoPixelBufferShader
// This example will provide a shader class to the NeoPixelBuffer that will dim and brighten
// the pixels that are in the buffer (a device dependent bitmap)
//
// the pixels that are in the buffer (a device independant bitmap)
// It is just a demonstration of using a custom shader
#include <NeoPixelBus.h>
@@ -14,7 +14,7 @@ NeoPixelBus<NeoGrbFeature, NeoWs2812xMethod> strip(PixelCount, PixelPin);
// the buffer object,
// defined to use memory with the same feature as the strip
// initialized with the same number of pixels as our strip
NeoBuffer<NeoBufferMethod<NeoGrbFeature>> image(8,8,NULL);
NeoBuffer<NeoBufferMethod<RgbColor>> image(8, 8, NULL);
const RgbColor BrightRed(255, 0, 0);
const RgbColor BrightGreen(0, 255, 0);
@@ -36,53 +36,40 @@ const RgbColor White(255);
const RgbColor Black(0);
// define a custom shader object that provides brightness support
// based upon the NeoShaderBase
template<typename T_COLOR_FEATURE> class BrightnessShader : public NeoShaderBase
class BrightnessShader
{
public:
BrightnessShader():
NeoShaderBase(),
_brightness(255) // default to full bright
{}
BrightnessShader() :
_brightness(255) // default to full bright
{}
// required for a shader object, it will be called for
// every pixel
void Apply(uint16_t index, uint8_t* pDest, const uint8_t* pSrc)
{
// we don't care what the index is so we ignore it
//
// to apply our brightness shader,
// use the source color, modify, and apply to the destination
// for every byte in the pixel,
// scale the source value by the brightness and
// store it in the destination byte
const uint8_t* pSrcEnd = pSrc + T_COLOR_FEATURE::PixelSize;
while (pSrc != pSrcEnd)
// required for a shader object, it will be called for
// every pixel
RgbColor Apply(const RgbColor& color)
{
*pDest++ = (*pSrc++ * (uint16_t(_brightness) + 1)) >> 8;
// to apply our brightness shader,
// use the source color, modify, and return it
return color.Dim(_brightness);
}
}
// provide an accessor to set brightness
void setBrightness(uint8_t brightness)
{
_brightness = brightness;
Dirty(); // must call dirty when a property changes
}
// provide an accessor to set brightness
void setBrightness(uint8_t brightness)
{
_brightness = brightness;
}
// provide an accessor to get brightness
uint8_t getBrightness()
{
return _brightness;
}
// provide an accessor to get brightness
uint8_t getBrightness()
{
return _brightness;
}
private:
uint8_t _brightness;
uint8_t _brightness;
};
// create an instance of our shader object with the same feature as our buffer
BrightnessShader<NeoGrbFeature> shader;
// create an instance of our shader object
BrightnessShader shader;
// some dimming tracking variables and settings
int8_t delta;
@@ -103,7 +90,7 @@ void setup()
// dibs do not default to any color,
// so clear it to black if you aren't going to draw
// into every pixel
image.ClearTo(Black);
image.ClearTo(Black);
// draw a pattern into the image
uint8_t x = 0;
@@ -123,7 +110,7 @@ void setup()
image.SetPixelColor(x++, y, BrightCyan);
image.SetPixelColor(x++, y, BrightBlue);
image.SetPixelColor(x++, y, BrightPurple);
Serial.println();
Serial.println("Running...");
@@ -132,36 +119,32 @@ void setup()
void loop()
{
// we increment by delta every 30ms
delay(30);
// update the brightness in shader
//
uint8_t brightness = shader.getBrightness();
// check if we flip directions
if (brightness == 0)
{
delta = 1; // increment
}
else if (brightness == 255)
{
delta = -1; // decrement
}
// modify and apply
brightness += delta;
shader.setBrightness(brightness);
Serial.println(brightness);
// render the image using the shader and then call Show()
// these two should be called together in order
//
// we increment by delta every 30ms
delay(30);
// need to provide the type of color feature for the strip and
// the type of our custom shader
image.Render<BrightnessShader<NeoGrbFeature>>(strip, shader);
strip.Show();
// update the brightness in shader
//
uint8_t brightness = shader.getBrightness();
// check if we flip directions
if (brightness == 0)
{
delta = 1; // increment
}
else if (brightness == 255)
{
delta = -1; // decrement
}
// modify and apply
brightness += delta;
shader.setBrightness(brightness);
Serial.println(brightness);
// render the image using the shader and then call Show()
// these two should be called together in order
//
image.Render<BrightnessShader>(strip, shader);
strip.Show();
}
@@ -1,158 +0,0 @@
// NeoPixelDibTest
// This example will provide a shader class to the NeoPixelDib that will dim and brighten
// the pixels that are in the Dib (Device Independant Bitmap)
//
#include <NeoPixelBus.h>
const uint16_t PixelCount = 64; // set this to the size of your strip
const uint8_t PixelPin = 2; // make sure to set this to the correct pin, ignored for Esp8266
// three element GRB pixels, change to your needs
NeoPixelBus<NeoGrbFeature, NeoWs2812xMethod> strip(PixelCount, PixelPin);
// the DIB object, using RgbColor and initialized with the same number of pixels as our strip
NeoDib<RgbColor> image(PixelCount);
const RgbColor BrightRed(255, 0, 0);
const RgbColor BrightGreen(0, 255, 0);
const RgbColor BrightBlue(0, 0, 255);
const RgbColor BrightYellow(255, 255, 0);
const RgbColor BrightCyan(0, 255, 255);
const RgbColor BrightPurple(255, 0, 255);
const RgbColor DarkRed(32, 0, 0);
const RgbColor DarkGreen(0, 32, 0);
const RgbColor DarkBlue(0, 0, 32);
const RgbColor DarkYellow(32, 32, 0);
const RgbColor DarkCyan(0, 32, 32);
const RgbColor DarkPurple(32, 0, 32);
const RgbColor White(255);
const RgbColor Black(0);
// define a custom shader object that provides brightness support
// based upon the NeoShaderBase
class BrightnessShader : public NeoShaderBase
{
public:
BrightnessShader():
NeoShaderBase(),
_brightness(255) // default to full bright
{}
// required for a shader object, it will be called for
// every pixel
RgbColor Apply(uint16_t index, RgbColor original)
{
// we don't care what the index is so we ignore it
//
// to apply our brightness shader, modify the original color and return the color we want
// blend from black (_brightness == 0.0) to the original color (_brightness == 1.0)
return RgbColor::LinearBlend(Black, original, (float)_brightness / 255.0f);
}
// provide an accessor to set brightness
void setBrightness(uint8_t brightness)
{
_brightness = brightness;
Dirty(); // must call dirty when a property changes
}
// provide an accessor to get brightness
uint8_t getBrightness()
{
return _brightness;
}
private:
uint8_t _brightness;
};
// create an instance of our shader object
BrightnessShader shader;
// some dimming tracking variables and settings
int8_t delta;
void setup()
{
Serial.begin(115200);
while (!Serial); // wait for serial attach
Serial.println();
Serial.println("Initializing...");
Serial.flush();
// this resets all the neopixels to an off state
strip.Begin();
strip.Show();
// dibs do not default to any color,
// so clear it to black if you aren't going to draw
// into every pixel
image.ClearTo(Black);
// draw a pattern into the image
uint8_t index = 0;
image.SetPixelColor(index++, DarkRed);
image.SetPixelColor(index++, DarkYellow);
image.SetPixelColor(index++, DarkGreen);
image.SetPixelColor(index++, DarkCyan);
image.SetPixelColor(index++, DarkBlue);
image.SetPixelColor(index++, DarkPurple);
image.SetPixelColor(index++, Black);
image.SetPixelColor(index++, Black);
image.SetPixelColor(index++, BrightRed);
image.SetPixelColor(index++, BrightYellow);
image.SetPixelColor(index++, BrightGreen);
image.SetPixelColor(index++, BrightCyan);
image.SetPixelColor(index++, BrightBlue);
image.SetPixelColor(index++, BrightPurple);
Serial.println();
Serial.println("Running...");
delta = -1; // start by dimming downward
}
void loop()
{
// we increment by delta every 30ms
delay(30);
// update the brightness in shader
//
uint8_t brightness = shader.getBrightness();
// check if we flip directions
if (brightness == 0)
{
delta = 1; // increment
}
else if (brightness == 255)
{
delta = -1; // decrement
}
// modify and apply
brightness += delta;
shader.setBrightness(brightness);
Serial.println(brightness);
// render the image using the shader and then call Show()
// these two should be called together in order
//
// need to provide the type of color feature for the strip and
// the type of our custom shader
image.Render<NeoGrbFeature, BrightnessShader>(strip, shader);
strip.Show();
}