Skip to content

Commit

Permalink
Topology, Curves, Gamma, and Samples
Browse files Browse the repository at this point in the history
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
Makuna committed Mar 20, 2016
1 parent 22f5e71 commit 3dbfae7
Show file tree
Hide file tree
Showing 30 changed files with 1,917 additions and 110 deletions.
14 changes: 6 additions & 8 deletions ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ A library to control one wire protocol RGB and RGBW leds like SK6812, WS2811, an
Supports most Arduino platforms.
This is the most funtional library for the Esp8266 as it provides solutions for all Esp8266 module types even when WiFi is used.


Please read this best practices link before connecting your NeoPixels, it will save you alot of time and effort.
[Adafruit NeoPixel Best Practices](https://learn.adafruit.com/adafruit-neopixel-uberguide/best-practices)

Expand All @@ -16,21 +17,18 @@ For quick questions jump on Gitter and ask away.

For bugs, make sure there isn't an active issue and then create one.

This new library supports a templatized model of defining which method gets used to send data and what order and size the pixel data is sent in. This new design creates the smallest code for each definition of features used. Further it allows for picking which method to send the data on the Esp8266 in an easy to change way.
Please see examples to become familiar with the new design.
Due to this design you will often realize over 500 bytes of more program storage for your sketch. Important for the smallest Arduinos project.

## Documentation
[See Wiki](https://github.com/Makuna/NeoPixelBus/wiki)

## Installing This Library (prefered)
## Installing This Library (prefered, you just want to use it)
Open the Library Manager and search for "NeoPixelBus by Makuna" and install

## Installing This Library From GitHub
## Installing This Library From GitHub (advanced, you want to contribute)
Create a directory in your Arduino\Library folder named "NeoPixelBus"
Clone (Git) this project into that folder.
It should now show up in the import list when you restart Arduino IDE.

## Documentation
[See Wiki](https://github.com/Makuna/NeoPixelBus/wiki)




121 changes: 121 additions & 0 deletions examples/NeoPixelCylon/NeoPixelCylon.ino
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();
}
93 changes: 93 additions & 0 deletions examples/NeoPixelGamma/NeoPixelGamma.ino
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);
}
98 changes: 98 additions & 0 deletions examples/NeoPixelMosaicDump/NeoPixelMosaicDump.ino
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()
{

}

Loading

0 comments on commit 3dbfae7

Please sign in to comment.