Skip to content

Commit 2c07835

Browse files
committed
Merge pull request #86 from Makuna/NewExamples
Topology, Tiles, Mosaic, Gamma, and samples
2 parents 22f5e71 + 0b68628 commit 2c07835

30 files changed

Lines changed: 1935 additions & 109 deletions

ReadMe.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ A library to control one wire protocol RGB and RGBW leds like SK6812, WS2811, an
88
Supports most Arduino platforms.
99
This is the most funtional library for the Esp8266 as it provides solutions for all Esp8266 module types even when WiFi is used.
1010

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

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

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

19-
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.
20-
Please see examples to become familiar with the new design.
21-
Due to this design you will often realize over 500 bytes of more program storage for your sketch. Important for the smallest Arduinos project.
22-
20+
## Documentation
21+
[See Wiki](https://github.com/Makuna/NeoPixelBus/wiki)
2322

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

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

32-
## Documentation
33-
[See Wiki](https://github.com/Makuna/NeoPixelBus/wiki)
31+
3432

3533

3634

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
// NeoPixelCylon
2+
// This example will move a Cylong Red Eye back and forth across the
3+
// the full collection of pixels on the strip.
4+
//
5+
// This will demonstrate the use of the NeoEase animation ease methods; that provide
6+
// simulated acceleration to the animations.
7+
//
8+
//
9+
10+
#include <NeoPixelBus.h>
11+
#include <NeoPixelAnimator.h>
12+
13+
const uint16_t PixelCount = 16; // make sure to set this to the number of pixels in your strip
14+
const uint8_t PixelPin = 2; // make sure to set this to the correct pin, ignored for Esp8266
15+
const RgbColor CylonEyeColor(HtmlColor(0x7f0000));
16+
17+
NeoPixelBus<NeoGrbFeature, Neo800KbpsMethod> strip(PixelCount, PixelPin);
18+
19+
NeoPixelAnimator animations(2); // only ever need 2 animations
20+
21+
uint16_t lastPixel = 0; // track the eye position
22+
int8_t moveDir = 1; // track the direction of movement
23+
24+
// uncomment one of the lines below to see the effects of
25+
// changing the ease function on the movement animation
26+
AnimEaseFunction moveEase =
27+
// NeoEase::Linear;
28+
// NeoEase::QuadraticInOut;
29+
// NeoEase::CubicInOut;
30+
NeoEase::QuarticInOut;
31+
// NeoEase::QuinticInOut;
32+
// NeoEase::SinusoidalInOut;
33+
// NeoEase::ExponentialInOut;
34+
// NeoEase::CircularInOut;
35+
36+
void FadeAll(uint8_t darkenBy)
37+
{
38+
RgbColor color;
39+
for (uint16_t indexPixel = 0; indexPixel < strip.PixelCount(); indexPixel++)
40+
{
41+
color = strip.GetPixelColor(indexPixel);
42+
color.Darken(darkenBy);
43+
strip.SetPixelColor(indexPixel, color);
44+
}
45+
}
46+
47+
void FadeAnimUpdate(const AnimationParam& param)
48+
{
49+
if (param.state == AnimationState_Completed)
50+
{
51+
FadeAll(10);
52+
animations.RestartAnimation(param.index);
53+
}
54+
}
55+
56+
void MoveAnimUpdate(const AnimationParam& param)
57+
{
58+
// apply the movement animation curve
59+
float progress = moveEase(param.progress);
60+
61+
// use the curved progress to calculate the pixel to effect
62+
uint16_t nextPixel;
63+
if (moveDir > 0)
64+
{
65+
nextPixel = progress * PixelCount;
66+
}
67+
else
68+
{
69+
nextPixel = (1.0f - progress) * PixelCount;
70+
}
71+
72+
// if progress moves fast enough, we may move more than
73+
// one pixel, so we update all between the calculated and
74+
// the last
75+
if (lastPixel != nextPixel)
76+
{
77+
for (uint16_t i = lastPixel + moveDir; i != nextPixel; i += moveDir)
78+
{
79+
strip.SetPixelColor(i, CylonEyeColor);
80+
}
81+
}
82+
strip.SetPixelColor(nextPixel, CylonEyeColor);
83+
84+
lastPixel = nextPixel;
85+
86+
if (param.state == AnimationState_Completed)
87+
{
88+
// reverse direction of movement
89+
moveDir *= -1;
90+
91+
// done, time to restart this position tracking animation/timer
92+
animations.RestartAnimation(param.index);
93+
}
94+
}
95+
96+
void SetupAnimations()
97+
{
98+
// fade all pixels providing a tail that is longer the faster
99+
// the pixel moves.
100+
animations.StartAnimation(0, 5, FadeAnimUpdate);
101+
102+
// take several seconds to move eye fron one side to the other
103+
animations.StartAnimation(1, 2000, MoveAnimUpdate);
104+
}
105+
106+
void setup()
107+
{
108+
strip.Begin();
109+
strip.Show();
110+
111+
SetupAnimations();
112+
}
113+
114+
void loop()
115+
{
116+
// this is all that is needed to keep it running
117+
// and avoiding using delay() is always a good thing for
118+
// any timing related routines
119+
animations.UpdateAnimations();
120+
strip.Show();
121+
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
// NeoPixelGamma
2+
// This example will display a timed series of color gradiants with gamma correction
3+
// and then without.
4+
// If the last pixel is on, then the colors being shown are color corrected.
5+
// It will show Red grandiant, Green grandiant, Blue grandiant, a White grandiant, and
6+
// then repeat.
7+
//
8+
// This will demonstrate the use of the NeoGamma class
9+
//
10+
//
11+
12+
#include <NeoPixelBus.h>
13+
#include <NeoPixelAnimator.h>
14+
15+
const uint16_t PixelCount = 16; // make sure to set this to the number of pixels in your strip
16+
const uint8_t PixelPin = 2; // make sure to set this to the correct pin, ignored for Esp8266
17+
18+
NeoPixelBus<NeoGrbFeature, Neo800KbpsMethod> strip(PixelCount, PixelPin);
19+
20+
// uncomment only one of these to compare memory use or speed
21+
//
22+
// NeoGamma<NeoGammaEquationMethod> colorGamma;
23+
NeoGamma<NeoGammaTableMethod> colorGamma;
24+
25+
void DrawPixels(bool corrected, HslColor startColor, HslColor stopColor)
26+
{
27+
for (uint16_t index = 0; index < strip.PixelCount() - 1; index++)
28+
{
29+
float progress = index / static_cast<float>(strip.PixelCount() - 2);
30+
RgbColor color = HslColor::LinearBlend(startColor, stopColor, progress);
31+
if (corrected)
32+
{
33+
color = colorGamma.Correct(color);
34+
}
35+
strip.SetPixelColor(index, color);
36+
}
37+
38+
// use the last pixel to indicate if we are showing corrected colors or not
39+
if (corrected)
40+
{
41+
strip.SetPixelColor(strip.PixelCount() - 1, RgbColor(64));
42+
}
43+
else
44+
{
45+
strip.SetPixelColor(strip.PixelCount() - 1, RgbColor(0));
46+
}
47+
48+
strip.Show();
49+
}
50+
51+
void setup()
52+
{
53+
strip.Begin();
54+
strip.Show();
55+
}
56+
57+
void loop()
58+
{
59+
HslColor startColor;
60+
HslColor stopColor;
61+
62+
// red color
63+
startColor = HslColor(0.0f, 1.0f, 0.0f);
64+
stopColor = HslColor(0.0f, 1.0f, 0.5f);
65+
DrawPixels(true, startColor, stopColor);
66+
delay(5000);
67+
DrawPixels(false, startColor, stopColor);
68+
delay(5000);
69+
70+
// green color
71+
startColor = HslColor(0.33f, 1.0f, 0.0f);
72+
stopColor = HslColor(0.33f, 1.0f, 0.5f);
73+
DrawPixels(true, startColor, stopColor);
74+
delay(5000);
75+
DrawPixels(false, startColor, stopColor);
76+
delay(5000);
77+
78+
// blue color
79+
startColor = HslColor(0.66f, 1.0f, 0.0f);
80+
stopColor = HslColor(0.66f, 1.0f, 0.5f);
81+
DrawPixels(true, startColor, stopColor);
82+
delay(5000);
83+
DrawPixels(false, startColor, stopColor);
84+
delay(5000);
85+
86+
// white color
87+
startColor = HslColor(0.0f, 0.0f, 0.0f);
88+
stopColor = HslColor(0.0f, 0.0f, 0.5f);
89+
DrawPixels(true, startColor, stopColor);
90+
delay(5000);
91+
DrawPixels(false, startColor, stopColor);
92+
delay(5000);
93+
}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
//----------------------------------------------------------------------
2+
// NeoPixelMosaicDump
3+
// This will dump to the serial output a grid map of the defined mosaic
4+
// The output is displayed as row column labeled grid with the NeoPixelBus
5+
// index of the pixel at the intersection of the row and column.
6+
//
7+
// To help with physical layout, there maybe included a symbol following the index
8+
// < means the index is the input index for the panel, the first on the panel
9+
// > means the index is the output index for the panel, the last on the panel
10+
//
11+
// This is useful in visualising the mosaic layout of your panels to
12+
// confirm you have them correctly wired together for this mosaic pattern
13+
//
14+
// It does not require that you have the actual panel connected
15+
//----------------------------------------------------------------------
16+
17+
#include <NeoPixelAnimator.h>
18+
#include <NeoPixelBus.h>
19+
20+
// uncomment one of these that matches your panel pixel layouts
21+
// rotation is ignored for mosaic as it applies a rotation for you
22+
// that is specific to the location of the panel within the mosaic
23+
// to reduce connection lengths
24+
25+
typedef ColumnMajorAlternatingLayout MyPanelLayout;
26+
// typedef ColumnMajorLayout MyPanelLayout;
27+
// typedef RowMajorAlternatingLayout MyPanelLayout;
28+
// typedef RowMajorLayout MyPanelLayout;
29+
30+
// make sure to set these panel and tile layout to match your sizes
31+
const uint8_t PanelWidth = 8; // a 8 pixel x 8 pixel matrix of leds on the panel
32+
const uint8_t PanelHeight = 8;
33+
const uint8_t TileWidth = 4; // laid out in 4 panels x 2 panels mosaic
34+
const uint8_t TileHeight = 2;
35+
36+
NeoMosaic <MyPanelLayout> mosaic(
37+
PanelWidth,
38+
PanelHeight,
39+
TileWidth,
40+
TileHeight);
41+
42+
void DumpMosaic()
43+
{
44+
Serial.println();
45+
46+
Serial.print("\t\t");
47+
for (int x = 0; x < mosaic.getWidth(); x++)
48+
{
49+
Serial.print(x);
50+
Serial.print("\t");
51+
}
52+
Serial.println();
53+
54+
Serial.print("\t---");
55+
for (int x = 0; x < mosaic.getWidth(); x++)
56+
{
57+
Serial.print("--------");
58+
}
59+
Serial.println();
60+
61+
for (int y = 0; y < mosaic.getHeight(); y++)
62+
{
63+
Serial.print(" ");
64+
Serial.print(y);
65+
Serial.print("\t|\t");
66+
67+
for (int x = 0; x < mosaic.getWidth(); x++)
68+
{
69+
NeoTopologyHint hint = mosaic.TopologyHint(x, y);
70+
71+
Serial.print(mosaic.Map(x, y));
72+
if (hint == NeoTopologyHint_FirstOnPanel)
73+
{
74+
Serial.print("<");
75+
}
76+
else if (hint == NeoTopologyHint_LastOnPanel)
77+
{
78+
Serial.print(">");
79+
}
80+
Serial.print("\t");
81+
}
82+
Serial.println();
83+
}
84+
}
85+
86+
void setup()
87+
{
88+
Serial.begin(115200);
89+
while (!Serial); // wait for serial attach
90+
91+
DumpMosaic();
92+
}
93+
94+
void loop()
95+
{
96+
97+
}
98+

0 commit comments

Comments
 (0)