-
-
Notifications
You must be signed in to change notification settings - Fork 264
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Topology, Curves, Gamma, and Samples
Topology, Tiles, and Mosaic layout Animation Curves Color Gamma correct change timescale dynamically on NeoPixelAnimator bilinear color blend methods new samples to support new features
- Loading branch information
Showing
30 changed files
with
1,917 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
// NeoPixelCylon | ||
// This example will move a Cylong Red Eye back and forth across the | ||
// the full collection of pixels on the strip. | ||
// | ||
// This will demonstrate the use of the NeoEase animation ease methods; that provide | ||
// simulated acceleration to the animations. | ||
// | ||
// | ||
|
||
#include <NeoPixelBus.h> | ||
#include <NeoPixelAnimator.h> | ||
|
||
const uint16_t PixelCount = 16; // make sure to set this to the number of pixels in your strip | ||
const uint8_t PixelPin = 2; // make sure to set this to the correct pin, ignored for Esp8266 | ||
const RgbColor CylonEyeColor(HtmlColor(0x7f0000)); | ||
|
||
NeoPixelBus<NeoGrbFeature, Neo800KbpsMethod> strip(PixelCount, PixelPin); | ||
|
||
NeoPixelAnimator animations(2); // only ever need 2 animations | ||
|
||
uint16_t lastPixel = 0; // track the eye position | ||
int8_t moveDir = 1; // track the direction of movement | ||
|
||
// uncomment one of the lines below to see the effects of | ||
// changing the ease function on the movement animation | ||
AnimEaseFunction moveEase = | ||
// NeoEase::Linear; | ||
// NeoEase::QuadraticInOut; | ||
// NeoEase::CubicInOut; | ||
NeoEase::QuarticInOut; | ||
// NeoEase::QuinticInOut; | ||
// NeoEase::SinusoidalInOut; | ||
// NeoEase::ExponentialInOut; | ||
// NeoEase::CircularInOut; | ||
|
||
void FadeAll(uint8_t darkenBy) | ||
{ | ||
RgbColor color; | ||
for (uint16_t indexPixel = 0; indexPixel < strip.PixelCount(); indexPixel++) | ||
{ | ||
color = strip.GetPixelColor(indexPixel); | ||
color.Darken(darkenBy); | ||
strip.SetPixelColor(indexPixel, color); | ||
} | ||
} | ||
|
||
void FadeAnimUpdate(const AnimationParam& param) | ||
{ | ||
if (param.state == AnimationState_Completed) | ||
{ | ||
FadeAll(10); | ||
animations.RestartAnimation(param.index); | ||
} | ||
} | ||
|
||
void MoveAnimUpdate(const AnimationParam& param) | ||
{ | ||
// apply the movement animation curve | ||
float progress = moveEase(param.progress); | ||
|
||
// use the curved progress to calculate the pixel to effect | ||
uint16_t nextPixel; | ||
if (moveDir > 0) | ||
{ | ||
nextPixel = progress * PixelCount; | ||
} | ||
else | ||
{ | ||
nextPixel = (1.0f - progress) * PixelCount; | ||
} | ||
|
||
// if progress moves fast enough, we may move more than | ||
// one pixel, so we update all between the calculated and | ||
// the last | ||
if (lastPixel != nextPixel) | ||
{ | ||
for (uint16_t i = lastPixel + moveDir; i != nextPixel; i += moveDir) | ||
{ | ||
strip.SetPixelColor(i, CylonEyeColor); | ||
} | ||
} | ||
strip.SetPixelColor(nextPixel, CylonEyeColor); | ||
|
||
lastPixel = nextPixel; | ||
|
||
if (param.state == AnimationState_Completed) | ||
{ | ||
// reverse direction of movement | ||
moveDir *= -1; | ||
|
||
// done, time to restart this position tracking animation/timer | ||
animations.RestartAnimation(param.index); | ||
} | ||
} | ||
|
||
void SetupAnimations() | ||
{ | ||
// fade all pixels providing a tail that is longer the faster | ||
// the pixel moves. | ||
animations.StartAnimation(0, 5, FadeAnimUpdate); | ||
|
||
// take several seconds to move eye fron one side to the other | ||
animations.StartAnimation(1, 2000, MoveAnimUpdate); | ||
} | ||
|
||
void setup() | ||
{ | ||
strip.Begin(); | ||
strip.Show(); | ||
|
||
SetupAnimations(); | ||
} | ||
|
||
void loop() | ||
{ | ||
// this is all that is needed to keep it running | ||
// and avoiding using delay() is always a good thing for | ||
// any timing related routines | ||
animations.UpdateAnimations(); | ||
strip.Show(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
// NeoPixelGamma | ||
// This example will display a timed series of color gradiants with gamma correction | ||
// and then without. | ||
// If the last pixel is on, then the colors being shown are color corrected. | ||
// It will show Red grandiant, Green grandiant, Blue grandiant, a White grandiant, and | ||
// then repeat. | ||
// | ||
// This will demonstrate the use of the NeoGamma class | ||
// | ||
// | ||
|
||
#include <NeoPixelBus.h> | ||
#include <NeoPixelAnimator.h> | ||
|
||
const uint16_t PixelCount = 16; // make sure to set this to the number of pixels in your strip | ||
const uint8_t PixelPin = 2; // make sure to set this to the correct pin, ignored for Esp8266 | ||
|
||
NeoPixelBus<NeoGrbFeature, Neo800KbpsMethod> strip(PixelCount, PixelPin); | ||
|
||
// uncomment only one of these to compare memory use or speed | ||
// | ||
// NeoGamma<NeoGammaEquationMethod> gamma; | ||
NeoGamma<NeoGammaTableMethod> gamma; | ||
|
||
void DrawPixels(bool corrected, HslColor startColor, HslColor stopColor) | ||
{ | ||
for (uint16_t index = 0; index < strip.PixelCount() - 1; index++) | ||
{ | ||
float progress = index / static_cast<float>(strip.PixelCount() - 2); | ||
RgbColor color = HslColor::LinearBlend(startColor, stopColor, progress); | ||
if (corrected) | ||
{ | ||
color = gamma.Correct(color); | ||
} | ||
strip.SetPixelColor(index, color); | ||
} | ||
|
||
// use the last pixel to indicate if we are showing corrected colors or not | ||
if (corrected) | ||
{ | ||
strip.SetPixelColor(strip.PixelCount() - 1, RgbColor(64)); | ||
} | ||
else | ||
{ | ||
strip.SetPixelColor(strip.PixelCount() - 1, RgbColor(0)); | ||
} | ||
|
||
strip.Show(); | ||
} | ||
|
||
void setup() | ||
{ | ||
strip.Begin(); | ||
strip.Show(); | ||
} | ||
|
||
void loop() | ||
{ | ||
HslColor startColor; | ||
HslColor stopColor; | ||
|
||
// red color | ||
startColor = HslColor(0.0f, 1.0f, 0.0f); | ||
stopColor = HslColor(0.0f, 1.0f, 0.5f); | ||
DrawPixels(true, startColor, stopColor); | ||
delay(5000); | ||
DrawPixels(false, startColor, stopColor); | ||
delay(5000); | ||
|
||
// green color | ||
startColor = HslColor(0.33f, 1.0f, 0.0f); | ||
stopColor = HslColor(0.33f, 1.0f, 0.5f); | ||
DrawPixels(true, startColor, stopColor); | ||
delay(5000); | ||
DrawPixels(false, startColor, stopColor); | ||
delay(5000); | ||
|
||
// blue color | ||
startColor = HslColor(0.66f, 1.0f, 0.0f); | ||
stopColor = HslColor(0.66f, 1.0f, 0.5f); | ||
DrawPixels(true, startColor, stopColor); | ||
delay(5000); | ||
DrawPixels(false, startColor, stopColor); | ||
delay(5000); | ||
|
||
// white color | ||
startColor = HslColor(0.0f, 0.0f, 0.0f); | ||
stopColor = HslColor(0.0f, 0.0f, 0.5f); | ||
DrawPixels(true, startColor, stopColor); | ||
delay(5000); | ||
DrawPixels(false, startColor, stopColor); | ||
delay(5000); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
//---------------------------------------------------------------------- | ||
// NeoPixelMosaicDump | ||
// This will dump to the serial output a grid map of the defined mosaic | ||
// The output is displayed as row column labeled grid with the NeoPixelBus | ||
// index of the pixel at the intersection of the row and column. | ||
// | ||
// To help with physical layout, there maybe included a symbol following the index | ||
// < means the index is the input index for the panel, the first on the panel | ||
// > means the index is the output index for the panel, the last on the panel | ||
// | ||
// This is useful in visualising the mosaic layout of your panels to | ||
// confirm you have them correctly wired together for this mosaic pattern | ||
// | ||
// It does not require that you have the actual panel connected | ||
//---------------------------------------------------------------------- | ||
|
||
#include <NeoPixelAnimator.h> | ||
#include <NeoPixelBus.h> | ||
|
||
// uncomment one of these that matches your panel pixel layouts | ||
// rotation is ignored for mosaic as it applies a rotation for you | ||
// that is specific to the location of the panel within the mosaic | ||
// to reduce connection lengths | ||
|
||
typedef ColumnMajorAlternatingLayout MyPanelLayout; | ||
// typedef ColumnMajorLayout MyPanelLayout; | ||
// typedef RowMajorAlternatingLayout MyPanelLayout; | ||
// typedef RowMajorLayout MyPanelLayout; | ||
|
||
// make sure to set these panel and tile layout to match your sizes | ||
const uint8_t PanelWidth = 8; // a 8 pixel x 8 pixel matrix of leds on the panel | ||
const uint8_t PanelHeight = 8; | ||
const uint8_t TileWidth = 4; // laid out in 4 panels x 2 panels mosaic | ||
const uint8_t TileHeight = 2; | ||
|
||
NeoMosaic <MyPanelLayout> mosaic( | ||
PanelWidth, | ||
PanelHeight, | ||
TileWidth, | ||
TileHeight); | ||
|
||
void DumpMosaic() | ||
{ | ||
Serial.println(); | ||
|
||
Serial.print("\t\t"); | ||
for (int x = 0; x < mosaic.getWidth(); x++) | ||
{ | ||
Serial.print(x); | ||
Serial.print("\t"); | ||
} | ||
Serial.println(); | ||
|
||
Serial.print("\t---"); | ||
for (int x = 0; x < mosaic.getWidth(); x++) | ||
{ | ||
Serial.print("--------"); | ||
} | ||
Serial.println(); | ||
|
||
for (int y = 0; y < mosaic.getHeight(); y++) | ||
{ | ||
Serial.print(" "); | ||
Serial.print(y); | ||
Serial.print("\t|\t"); | ||
|
||
for (int x = 0; x < mosaic.getWidth(); x++) | ||
{ | ||
NeoTopologyHint hint = mosaic.TopologyHint(x, y); | ||
|
||
Serial.print(mosaic.Map(x, y)); | ||
if (hint == NeoTopologyHint_FirstOnPanel) | ||
{ | ||
Serial.print("<"); | ||
} | ||
else if (hint == NeoTopologyHint_LastOnPanel) | ||
{ | ||
Serial.print(">"); | ||
} | ||
Serial.print("\t"); | ||
} | ||
Serial.println(); | ||
} | ||
} | ||
|
||
void setup() | ||
{ | ||
Serial.begin(115200); | ||
while (!Serial); // wait for serial attach | ||
|
||
DumpMosaic(); | ||
} | ||
|
||
void loop() | ||
{ | ||
|
||
} | ||
|
Oops, something went wrong.