#include <Arduino.h>
#include <NeoPixelBus.h>
#include <NeoPixelAnimator.h>
NeoGamma<NeoGammaTableMethod> colorGamma;
const unsigned int PixelCount[] = {13, 6, 6, 6, 6};
const byte PixelPin1 = 2;
const byte PixelPin2 = 3; //26
const byte PixelPin3 = 4; //30
const byte PixelPin4 = 5; //34
const byte PixelPin5 = 6; //38
NeoPixelBus<NeoGrbFeature, Neo800KbpsMethod> strip[] = {
{PixelCount[0], PixelPin1},
{PixelCount[1], PixelPin2},
{PixelCount[2], PixelPin3},
{PixelCount[3], PixelPin4},
{PixelCount[4], PixelPin5}};
byte stripCount = 5;
byte x = 0, y = 0, z = 0;
RgbColor alloff(0, 0, 0);
RgbColor randColor(RgbColor(100, 100, 100));
RgbColor white1 = colorGamma.Correct(RgbColor(100, 100, 100));
RgbColor red1 = colorGamma.Correct(RgbColor(150, 0, 0));
RgbColor green1 = colorGamma.Correct(RgbColor(0, 150, 0));
RgbColor blue1 = colorGamma.Correct(RgbColor(0, 10, 50));
RgbColor yellow1 = colorGamma.Correct(RgbColor(150, 150, 0));
RgbColor purple1 = colorGamma.Correct(RgbColor(150, 0, 150));
RgbColor orange1 = colorGamma.Correct(RgbColor(125, 75, 0));
RgbColor pink1 = colorGamma.Correct(RgbColor(100, 0, 50));
RgbColor cyan1 = colorGamma.Correct(RgbColor(0, 100, 100));
int k1 = 0;
void setup()
{
SerialUSB.begin(9600);
for (byte i = 0; i < stripCount; i++)
{
strip[i].Begin();
strip[i].Show();
}
}
void loop()
{
SerialUSB.println("redGreenChase");
for (int i = 0; i < 10; i++)
{
redGreenChase(350);
}
SerialUSB.println("whiteFade");
for (int i = 0; i < 20; i++)
{
whiteFade(1, 20, 200);
}
SerialUSB.println("pulse");
for (int i = 0; i < 15; i++)
{
pulse(0);
}
SerialUSB.println("rainbowFade");
for (int i = 0; i < 25; i++)
{
rainbowFade(0);
delay(75);
}
SerialUSB.println("radiate");
for (int i = 0; i < 20; i++)
{
radiate(1);
}
SerialUSB.println("rainbow");
for (int i = 0; i < 20; i++)
{
rainbow(0);
}
SerialUSB.println("spiral");
for (int i = 0; i < 20; i++)
{
spiral(1);
}
}
/////////////////////////////////////////////////////////////
void redGreenChase(int delayTime)
{
for (byte m = 0; m < stripCount; m++)
{
for (byte i = 0; i < PixelCount[m]; i += 2)
{
strip[m].SetPixelColor(i, red1);
strip[m].SetPixelColor(i + 1, green1);
}
}
for (byte i = 0; i < stripCount; i++)
{
strip[i].Show();
}
delay(delayTime);
for (byte i = 0; i < stripCount; i++)
{
strip[i].RotateRight(1);
strip[i].Show();
}
delay(delayTime);
}
/////////////////////////////////////////////////////////////
void whiteFade(byte delayTime, byte brightness, byte maxBrightness)
{
for (int i = 0; i < stripCount; i++)
{
for (int j = 0; j < PixelCount[i]; j++)
{
strip[i].SetPixelColor(j, RgbColor(brightness, brightness, brightness));
}
strip[i].Show();
}
byte b = random(stripCount);
byte d = random(stripCount);
byte a = random(PixelCount[b]);
byte c = random(PixelCount[d]);
for (int j = 0; j <= maxBrightness; j += 4)
{
strip[b].SetPixelColor(a, RgbColor(j, j, j));
strip[d].SetPixelColor(c, RgbColor(j, j, j));
strip[b].Show();
strip[d].Show();
delay(delayTime);
}
for (int j = maxBrightness; j >= brightness; j -= 4)
{
strip[b].SetPixelColor(a, RgbColor(j, j, j));
strip[d].SetPixelColor(c, RgbColor(j, j, j));
strip[d].Show();
strip[b].Show();
delay(delayTime);
}
}
////////////////////////////////////////////////////////////
void rainbowFade(byte delayTime)
{
// allOffNow();
for (byte i = 0; i < stripCount; i++)
{
byte a = random(PixelCount[i]);
byte b = random(PixelCount[i]);
RgbColor startColor = RgbColor(random(150), random(150), random(150));
RgbColor endColor = RgbColor(random(150), random(150), random(150));
// RgbColor updatedColor = RgbColor::LinearBlend(startColor, endColor, c);
// for (int j = 0; j < PixelCount[i]; j++)
// {
strip[i].SetPixelColor(a, colorGamma.Correct(startColor));
strip[i].Show();
delay(delayTime);
// RgbColor updatedColor = RgbColor::LinearBlend(startColor, endColor, c);
// // for (int j = 0; j < PixelCount[i]; j++)
// // {
// strip[i].SetPixelColor(j, colorGamma.Correct(updatedColor));
// strip[i].Show();
// delay(delayTime);
// }
// for (int j = 200; j >= 0; j -= 2)
// {
// strip[i].SetPixelColor(a, RgbColor(j, j, j));
// strip[i].Show();
// delay(delayTime);
// }
}
}
////////////////////////////////////////////////////////////
void pulse(byte delayTime)
{
allOffNow();
for (byte j = 0; j < 150; j += 2)
{
strip[0].SetPixelColor(6, RgbColor(j, j, j));
strip[0].Show();
delay(delayTime);
}
for (byte k = 0; k < 6; k++)
{
for (byte j = 0; j < 150; j += 2)
{
for (byte i = 0; i < stripCount; i++)
{
if (i == 0)
{
strip[0].SetPixelColor(k + 7, RgbColor(j, j, j));
strip[0].SetPixelColor(5 - k, RgbColor(j, j, j));
}
else
{
strip[i].SetPixelColor(k, RgbColor(j, j, j));
}
strip[i].Show();
delay(delayTime);
}
}
}
strip[0].SetPixelColor(6, RgbColor(0, 0, 0));
for (int k = 0; k < 6; k++)
{
for (int j = 150; j >= 0; j -= 2)
{
for (int i = 0; i < stripCount; i++)
{
if (i == 0)
{
strip[0].SetPixelColor(k + 7, RgbColor(j, j, j));
strip[0].SetPixelColor(5 - k, RgbColor(j, j, j));
}
else
{
strip[i].SetPixelColor(k, RgbColor(j, j, j));
}
strip[i].Show();
delay(delayTime);
}
}
}
}
////////////////////////////////////////////////////////////
void rainbow(byte delayTime)
{
allOffNow();
x = random(8);
switch (x)
{
case 0:
randColor = red1;
break;
case 1:
randColor = green1;
break;
case 2:
randColor = blue1;
break;
case 3:
randColor = yellow1;
break;
case 4:
randColor = purple1;
break;
case 5:
randColor = orange1;
break;
case 6:
randColor = pink1;
break;
case 7:
randColor = cyan1;
break;
}
for (int j = 0; j < 150; j += 2)
{
strip[0].SetPixelColor(6, randColor);
strip[0].Show();
delay(delayTime);
}
for (int k = 0; k < 6; k++)
{
for (int j = 0; j < 150; j += 4)
{
for (int i = 0; i < stripCount; i++)
{
if (i == 0)
{
strip[0].SetPixelColor(k + 7, randColor);
strip[0].SetPixelColor(5 - k, randColor);
}
else
{
strip[i].SetPixelColor(k, randColor);
}
strip[i].Show();
delay(delayTime);
}
}
}
strip[0].SetPixelColor(6, RgbColor(0, 0, 0));
for (int k = 0; k < 6; k++)
{
for (int j = 150; j >= 0; j -= 4)
{
for (int i = 0; i < stripCount; i++)
{
if (i == 0)
{
strip[0].SetPixelColor(k + 7, RgbColor(0, 0, 0));
strip[0].SetPixelColor(5 - k, RgbColor(0, 0, 0));
}
else
{
strip[i].SetPixelColor(k, RgbColor(0, 0, 0));
}
strip[i].Show();
delay(delayTime);
}
}
}
}
////////////////////////////////////////////////////////////
void radiate(byte delayTime)
{
allOffNow();
for (byte j = 0; j < 250; j += 2)
{
for (byte i = 0; i < stripCount; i++)
{
if (i == 0)
{
strip[0].SetPixelColor(5, RgbColor(j, j, j));
strip[0].SetPixelColor(7, RgbColor(j, j, j));
}
else
{
strip[i].SetPixelColor(0, RgbColor(j, j, j));
}
strip[i].Show();
delay(delayTime);
}
}
for (byte j = 252; j > 0; j -= 2)
{
for (byte i = 0; i < stripCount; i++)
{
if (i == 0)
{
strip[0].SetPixelColor(5, RgbColor(j, j, j));
strip[0].SetPixelColor(7, RgbColor(j, j, j));
}
else
{
strip[i].SetPixelColor(0, RgbColor(j, j, j));
}
strip[i].Show();
delay(delayTime);
}
}
for (byte j = 1; j < 6; j++)
{
for (byte k = 0; k < 150; k += 3)
{
for (byte i = 0; i < stripCount; i++)
{
if (i == 0)
{
strip[0].SetPixelColor(5 - j, RgbColor(k, k, k));
strip[0].SetPixelColor(7 + j, RgbColor(k, k, k));
if (j >= 2)
{
strip[i].SetPixelColor(6 - j, RgbColor(0, 0, 0));
strip[i].SetPixelColor(6 + j, RgbColor(0, 0, 0));
}
}
else
{
strip[i].SetPixelColor(j, RgbColor(k, k, k));
if (j >= 2)
{
strip[i].SetPixelColor(j - 1, RgbColor(0, 0, 0));
}
}
strip[i].Show();
// delay(delayTime);
}
}
}
}
////////////////////////////////////////////////////////////
void spiral(int delayTime)
{
strip[0].SetPixelColor(6, white1);
strip[0].Show();
delay(delayTime);
allOffNow();
for (int j = 0; j < 5; j++)
{
for (int k = 0; k < stripCount; k++)
{
if (k == 0)
{
strip[0].SetPixelColor(5 - j, white1);
strip[0].SetPixelColor(7 + j, white1);
}
else
{
strip[k].SetPixelColor(j, white1);
}
strip[k].Show();
// SerialUSB.println(i);
}
// delayTime = pow(delayTime,1.6);
delayTime += 40;
delay(delayTime);
allOffNow();
}
for (int j = 5; j > 0; j--)
{
for (int k = 0; k < stripCount; k++)
{
if (k == 0)
{
strip[0].SetPixelColor(5 - j, white1);
strip[0].SetPixelColor(7 + j, white1);
}
else
{
strip[k].SetPixelColor(j, white1);
}
strip[k].Show();
// SerialUSB.println(i);
}
delayTime -= 40;
delay(delayTime);
allOffNow();
}
}
////////////////////////////////////////////////////////////
void allOffNow()
{
for (byte m = 0; m < stripCount; m++)
{
for (byte j = 0; j < PixelCount[m]; j++)
{
strip[m].SetPixelColor(j, RgbColor(0, 0, 0));
strip[m].Show();
}
}
}
Comments