functional (#643)

This commit is contained in:
Michael Miller
2023-02-08 14:37:33 -08:00
committed by GitHub
parent 7822ea975e
commit fff81b9a15
5 changed files with 256 additions and 91 deletions
@@ -1,87 +0,0 @@
// NeoPixelBrightness
// This example will cycle brightness from high to low of
// three pixels colored Red, Green, Blue.
// This demonstrates the use of the NeoPixelBrightnessBus
// with integrated brightness support
//
// There is serial output of the current state so you can
// confirm and follow along
//
#include <NeoPixelBrightnessBus.h> // instead of NeoPixelBus.h
const uint16_t PixelCount = 3; // this example assumes 3 pixels, making it smaller will cause a failure
const uint8_t PixelPin = 14; // make sure to set this to the correct pin, ignored for Esp8266
#define colorSaturation 255 // saturation of color constants
RgbColor red(colorSaturation, 0, 0);
RgbColor green(0, colorSaturation, 0);
RgbColor blue(0, 0, colorSaturation);
// Make sure to provide the correct color order feature
// for your NeoPixels
NeoPixelBrightnessBus<NeoRgbFeature, Neo800KbpsMethod> strip(PixelCount, PixelPin);
// you loose the original color the lower the dim value used
// here due to quantization
const uint8_t c_MinBrightness = 8;
const uint8_t c_MaxBrightness = 255;
int8_t direction; // current direction of dimming
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();
direction = -1; // default to dim first
Serial.println();
Serial.println("Running...");
// set our three original colors
strip.SetPixelColor(0, red);
strip.SetPixelColor(1, green);
strip.SetPixelColor(2, blue);
strip.Show();
}
void loop()
{
uint8_t brightness = strip.GetBrightness();
Serial.println(brightness);
delay(100);
// swap diection of dim when limits are reached
//
if (direction < 0 && brightness <= c_MinBrightness)
{
direction = 1;
}
else if (direction > 0 && brightness >= c_MaxBrightness)
{
direction = -1;
}
// apply dimming
brightness += direction;
strip.SetPixelColor(0, red);
strip.SetPixelColor(1, green);
strip.SetPixelColor(2, blue);
strip.SetBrightness(brightness);
// show the results
strip.Show();
}
+105
View File
@@ -0,0 +1,105 @@
// NeoPixelBusLg
//
// This example demonstrates the use of the NeoPixelBusLg
// with integrated luminance and gamma support
//
// There is serial output of the current state so you can
// confirm and follow along
//
#include <NeoPixelBusLg.h> // instead of NeoPixelBus.h
const uint16_t PixelCount = 96; // set to the number of pixels in your strip
const uint8_t PixelPin = 14; // make sure to set this to the correct pin, ignored for Esp8266
RgbColor red(255, 0, 0);
RgbColor green(0, 255, 0);
RgbColor blue(0, 0, 255);
RgbColor black(0, 0, 0);
RgbColor white(255, 255, 255);
// Make sure to provide the correct color order feature
// for your NeoPixels
NeoPixelBusLg<NeoRgbFeature, NeoWs2812xMethod> strip(PixelCount, PixelPin);
// If speed is an issue and memory is not, then you can use the gama table variant
// which is much faster but uses 256 bytes of RAM
// NeoPixelBusLg<NeoRgbFeature, NeoWs2812xMethod, NeoGammaTableMethod> strip(PixelCount, PixelPin);
// If you want to turn gama correction off, then you can use the null gama method
// NeoPixelBusLg<NeoRgbFeature, NeoWs2812xMethod, NeoGammaNullMethod> strip(PixelCount, PixelPin);
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.SetLuminance(128); // (0-255) - initially at half brightness
strip.Show();
Serial.println();
Serial.println("Running...");
}
void loop()
{
static const uint8_t c_MinBrightness = 0;
static const uint8_t c_MaxBrightness = 255;
static int8_t direction = -1; // start with dimming
uint8_t luminance = strip.GetLuminance();
Serial.print(direction);
Serial.print(" ");
Serial.println(luminance);
delay(200);
// swap direction of luminance when limits are reached
//
if (direction < 0 && luminance <= c_MinBrightness)
{
direction = 1;
}
else if (direction > 0 && luminance >= c_MaxBrightness)
{
direction = -1;
}
else
{
luminance += direction;
}
strip.SetLuminance(luminance);
// draw something
//
uint16_t half = strip.PixelCount() / 2;
DrawGradiant(green, black, 0, half - 1);
DrawGradiant(black, red, half, strip.PixelCount() - 1);
// show the results
strip.Show();
}
void DrawGradiant(RgbColor startColor,
RgbColor finishColor,
uint16_t startIndex,
uint16_t finishIndex)
{
uint16_t delta = finishIndex - startIndex;
for (uint16_t index = startIndex; index < finishIndex; index++)
{
float progress = static_cast<float>(index - startIndex) / delta;
RgbColor color = RgbColor::LinearBlend(startColor, finishColor, progress);
strip.SetPixelColor(index, color);
}
}