Code...
#include <FastLED.h>
#define LED_PIN 7
#define NUM_LEDS 256
#define LED_TYPE WS2812B
#define COLOR_ORDER GRB
#define DEFAULT_FRAME_RATE 20
#define BRIGHTNESS 150 // 255 is brightest
// Pattern modes must be less than 10
#define CYCLE 1
#define SINGLE_PANEL_BACK_AND_FORTH 2
#define MULTI_PANEL 3
#define RAINBOW 4
#define SINGLE_PANEL_PULL_FORWARD 5
#define GRADIENT_PULSE 6
CRGB leds[NUM_LEDS];
CRGB rainbowPalette[16] =
{
{ 255, 0, 0 },
{ 255, 66, 0 },
{ 255, 192, 0 },
{ 222, 255, 0 },
{ 126, 255, 0 },
{ 30, 255, 0 },
{ 0, 255, 40 },
{ 0, 255, 162 },
{ 0, 252, 255 },
{ 0, 162, 255 },
{ 0, 66, 255 },
{ 30, 0, 255 },
{ 66, 0, 255 },
{ 180, 0, 255 },
{ 255, 0, 192 },
{ 255, 0, 96 }
};
CRGB gradientTrailPalette[16];
CRGB longBufferPalette[32];
int gradientArray[16] =
{ 255, 221, 187, 153, 119, 85, 51, 17, 0, 0, 0, 0, 0, 0, 0, 0 };
int rowIndex = 0;
int ledsPerRow = 16;
int numPanels = 16;
int framesPerSecond = DEFAULT_FRAME_RATE;
int currentBrightness = BRIGHTNESS;
byte currentGradientPulseIteration = 0;
int patternMode = 3; ////Pattern Mode is the KEY, Look here - change the number in the loop via button press
void setup()
{
Serial.begin( 115200 );
FastLED.setMaxPowerInVoltsAndMilliamps(5, 500);
delay( 3000 ); // power-up safety delay
FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
FastLED.setBrightness( BRIGHTNESS );
}
void loop()
{
{
FastLED.clear();
FastLED.show();
}
if ( patternMode == CYCLE )
{
// Single colored panels moving back and forth
for ( int inx = 0; patternMode == CYCLE && inx < 3; inx++ )
{
cycleBySinglePanel( CRGB::Red, ledsPerRow, numPanels, framesPerSecond, true );
cycleBySinglePanel( CRGB::Red, ledsPerRow, numPanels, framesPerSecond, false );
cycleBySinglePanel( CRGB::Indigo, ledsPerRow, numPanels, framesPerSecond, true );
cycleBySinglePanel( CRGB::Indigo, ledsPerRow, numPanels, framesPerSecond, false );
cycleBySinglePanel( CRGB::Green, ledsPerRow, numPanels, framesPerSecond, true );
cycleBySinglePanel( CRGB::Green, ledsPerRow, numPanels, framesPerSecond, false );
cycleBySinglePanel( CRGB::Blue, ledsPerRow, numPanels, framesPerSecond, true );
cycleBySinglePanel( CRGB::Blue, ledsPerRow, numPanels, framesPerSecond, false );
}
// Single colored panels moving forward only
for ( int inx = 0; patternMode == CYCLE && inx < 3; inx++ )
{
cycleBySinglePanel( CRGB::Red, ledsPerRow, numPanels, framesPerSecond, true );
cycleBySinglePanel( CRGB::Red, ledsPerRow, numPanels, framesPerSecond, true );
cycleBySinglePanel( CRGB::Yellow, ledsPerRow, numPanels, framesPerSecond, true );
cycleBySinglePanel( CRGB::Yellow, ledsPerRow, numPanels, framesPerSecond, true );
cycleBySinglePanel( CRGB::Green, ledsPerRow, numPanels, framesPerSecond, true );
cycleBySinglePanel( CRGB::Green, ledsPerRow, numPanels, framesPerSecond, true );
cycleBySinglePanel( CRGB::Blue, ledsPerRow, numPanels, framesPerSecond, true );
cycleBySinglePanel( CRGB::Blue, ledsPerRow, numPanels, framesPerSecond, true );
}
// Moving "train" of 16 contiguous panels
for ( int inx = 0; patternMode == CYCLE && inx < 2; inx++ )
{
cycleFillPanel( CRGB::Red, ledsPerRow, numPanels, framesPerSecond, true );
cycleFillPanel( CRGB::Black, ledsPerRow, numPanels, framesPerSecond, true );
cycleFillPanel( CRGB::Yellow, ledsPerRow, numPanels, framesPerSecond, true );
cycleFillPanel( CRGB::Black, ledsPerRow, numPanels, framesPerSecond, true );
cycleFillPanel( CRGB::Green, ledsPerRow, numPanels, framesPerSecond, true );
cycleFillPanel( CRGB::Black, ledsPerRow, numPanels, framesPerSecond, true );
cycleFillPanel( CRGB::Blue, ledsPerRow, numPanels, framesPerSecond, true );
cycleFillPanel( CRGB::Black, ledsPerRow, numPanels, framesPerSecond, true );
cycleFillPanel( CRGB::Purple, ledsPerRow, numPanels, framesPerSecond, true );
cycleFillPanel( CRGB::Black, ledsPerRow, numPanels, framesPerSecond, true );
}
// Moving rainbow colors
for ( int jnx = 0; patternMode == CYCLE && jnx < 10; jnx++ )
{
for ( int inx = 0; patternMode == CYCLE && inx < numPanels; inx++ )
{
cycleRainbow( numPanels - 1 - inx, ledsPerRow, numPanels );
}
}
currentGradientPulseIteration = 0;
for ( int jnx = 0; patternMode == CYCLE && jnx < 13; jnx++ )
{
Serial.print( "jnx = " );
Serial.print( jnx );
Serial.print( " : currentGradientPulseIteration = " );
Serial.println( currentGradientPulseIteration );
// Gradient pulse
// Start from black to red
if ( currentGradientPulseIteration == 0 )
{
for ( int inx = 0; inx < 16; inx++ )
{
longBufferPalette[inx] = CRGB::Black;
}
for ( int inx = 16; inx < 32; inx++ )
{
longBufferPalette[inx][0] = gradientArray[inx - 16];
longBufferPalette[inx][1] = 0;
longBufferPalette[inx][2] = 0;
}
for ( int inx = 0; patternMode == CYCLE && inx < numPanels; inx++ )
{
cycleBufferPalette( inx, ledsPerRow, numPanels );
}
}
else if ( currentGradientPulseIteration == 1 )
{
// Then red to yellow
for ( int inx = 0; inx < 16; inx++ )
{
longBufferPalette[inx][0] = gradientArray[inx];
longBufferPalette[inx][1] = 0;
longBufferPalette[inx][2] = 0;
}
for ( int inx = 16; inx < 32; inx++ )
{
longBufferPalette[inx][0] = gradientArray[inx - 16];
longBufferPalette[inx][1] = gradientArray[inx - 16];
longBufferPalette[inx][2] = 0;
}
for ( int inx = 0; patternMode == CYCLE && inx < numPanels; inx++ )
{
cycleBufferPalette( inx, ledsPerRow, numPanels );
}
}
else if ( currentGradientPulseIteration == 2 )
{
// Then yellow to green
for ( int inx = 0; inx < 16; inx++ )
{
longBufferPalette[inx][0] = gradientArray[inx];
longBufferPalette[inx][1] = gradientArray[inx];
longBufferPalette[inx][2] = 0;
}
for ( int inx = 16; inx < 32; inx++ )
{
longBufferPalette[inx][0] = 0;
longBufferPalette[inx][1] = gradientArray[inx - 16];
longBufferPalette[inx][2] = 0;
}
for ( int inx = 0; patternMode == CYCLE && inx < numPanels; inx++ )
{
cycleBufferPalette( inx, ledsPerRow, numPanels );
}
}
else if ( currentGradientPulseIteration == 3 )
{
// Then green to cyan
for ( int inx = 0; inx < 16; inx++ )
{
longBufferPalette[inx][0] = 0;
longBufferPalette[inx][1] = gradientArray[inx];
longBufferPalette[inx][2] = 0;
}
for ( int inx = 16; inx < 32; inx++ )
{
longBufferPalette[inx][0] = 0;
longBufferPalette[inx][1] = gradientArray[inx - 16];
longBufferPalette[inx][2] = gradientArray[inx - 16];
}
for ( int inx = 0; patternMode == CYCLE && inx < numPanels; inx++ )
{
cycleBufferPalette( inx, ledsPerRow, numPanels );
}
}
else if ( currentGradientPulseIteration == 4 )
{
// Then cyan to blue
for ( int inx = 0; inx < 16; inx++ )
{
longBufferPalette[inx][0] = 0;
longBufferPalette[inx][1] = gradientArray[inx];
longBufferPalette[inx][2] = gradientArray[inx];
}
for ( int inx = 16; inx < 32; inx++ )
{
longBufferPalette[inx][0] = 0;
longBufferPalette[inx][1] = 0;
longBufferPalette[inx][2] = gradientArray[inx - 16];
}
for ( int inx = 0; patternMode == CYCLE && inx < numPanels; inx++ )
{
cycleBufferPalette( inx, ledsPerRow, numPanels );
}
}
else if ( currentGradientPulseIteration == 5 )
{
// Then blue to magenta
for ( int inx = 0; inx < 16; inx++ )
{
longBufferPalette[inx][0] = 0;
longBufferPalette[inx][1] = 0;
longBufferPalette[inx][2] = gradientArray[inx];
}
for ( int inx = 16; inx < 32; inx++ )
{
longBufferPalette[inx][0] = gradientArray[inx - 16];
longBufferPalette[inx][1] = 0;
longBufferPalette[inx][2] = gradientArray[inx - 16];
}
for ( int inx = 0; patternMode == CYCLE && inx < numPanels; inx++ )
{
cycleBufferPalette( inx, ledsPerRow, numPanels );
}
}
else if ( currentGradientPulseIteration == 6 )
{
// Then magenta to red
for ( int inx = 0; inx < 16; inx++ )
{
longBufferPalette[inx][0] = gradientArray[inx];
longBufferPalette[inx][1] = 0;
longBufferPalette[inx][2] = gradientArray[inx];
}
for ( int inx = 16; inx < 32; inx++ )
{
longBufferPalette[inx][0] = gradientArray[inx - 16];
longBufferPalette[inx][1] = 0;
longBufferPalette[inx][2] = 0;
}
for ( int inx = 0; patternMode == CYCLE && inx < numPanels; inx++ )
{
cycleBufferPalette( inx, ledsPerRow, numPanels );
}
}
currentGradientPulseIteration++;
if ( currentGradientPulseIteration == 7 )
{
// Don't want to go back to 0 because that
// was just the initializer with a starting block of black.
currentGradientPulseIteration = 1;
}
}
}
else if ( patternMode == SINGLE_PANEL_BACK_AND_FORTH )
{
cycleBySinglePanel( CRGB::Red, ledsPerRow, numPanels, framesPerSecond, true );
cycleBySinglePanel( CRGB::Red, ledsPerRow, numPanels, framesPerSecond, false );
cycleBySinglePanel( CRGB::Yellow, ledsPerRow, numPanels, framesPerSecond, true );
cycleBySinglePanel( CRGB::Yellow, ledsPerRow, numPanels, framesPerSecond, false );
cycleBySinglePanel( CRGB::Green, ledsPerRow, numPanels, framesPerSecond, true );
cycleBySinglePanel( CRGB::Green, ledsPerRow, numPanels, framesPerSecond, false );
cycleBySinglePanel( CRGB::Blue, ledsPerRow, numPanels, framesPerSecond, true );
cycleBySinglePanel( CRGB::Blue, ledsPerRow, numPanels, framesPerSecond, false );
}
else if ( patternMode == SINGLE_PANEL_PULL_FORWARD )
{
cycleBySinglePanel( CRGB::Red, ledsPerRow, numPanels, framesPerSecond, true );
cycleBySinglePanel( CRGB::Red, ledsPerRow, numPanels, framesPerSecond, true );
cycleBySinglePanel( CRGB::Yellow, ledsPerRow, numPanels, framesPerSecond, true );
cycleBySinglePanel( CRGB::Yellow, ledsPerRow, numPanels, framesPerSecond, true );
cycleBySinglePanel( CRGB::Green, ledsPerRow, numPanels, framesPerSecond, true );
cycleBySinglePanel( CRGB::Green, ledsPerRow, numPanels, framesPerSecond, true );
cycleBySinglePanel( CRGB::Blue, ledsPerRow, numPanels, framesPerSecond, true );
cycleBySinglePanel( CRGB::Blue, ledsPerRow, numPanels, framesPerSecond, true );
}
else if ( patternMode == MULTI_PANEL )
{
cycleFillPanel( CRGB::SkyBlue, ledsPerRow, numPanels, framesPerSecond, true );
cycleFillPanel( CRGB::SlateBlue, ledsPerRow, numPanels, framesPerSecond, true );
cycleFillPanel( CRGB::DarkSlateBlue, ledsPerRow, numPanels, framesPerSecond, true );
cycleFillPanel( CRGB::Aqua, ledsPerRow, numPanels, framesPerSecond, true );
cycleFillPanel( CRGB::Blue, ledsPerRow, numPanels, framesPerSecond, true );
cycleFillPanel( CRGB::DeepSkyBlue, ledsPerRow, numPanels, framesPerSecond, true );
cycleFillPanel( CRGB::DodgerBlue, ledsPerRow, numPanels, framesPerSecond, true );
cycleFillPanel( CRGB::PowderBlue, ledsPerRow, numPanels, framesPerSecond, true );
cycleFillPanel( CRGB::SteelBlue, ledsPerRow, numPanels, framesPerSecond, true );
cycleFillPanel( CRGB::LightBlue, ledsPerRow, numPanels, framesPerSecond, true );
cycleFillPanel( CRGB::LightSkyBlue, ledsPerRow, numPanels, framesPerSecond, true );
cycleFillPanel( CRGB::LightSteelBlue, ledsPerRow, numPanels, framesPerSecond, true );
cycleFillPanel( CRGB::MediumAquamarine, ledsPerRow, numPanels, framesPerSecond, true );
cycleFillPanel( CRGB::MidnightBlue, ledsPerRow, numPanels, framesPerSecond, true );
cycleFillPanel( CRGB::MediumBlue, ledsPerRow, numPanels, framesPerSecond, true );
cycleFillPanel( CRGB::RoyalBlue, ledsPerRow, numPanels, framesPerSecond, true );
cycleFillPanel( CRGB::Teal, ledsPerRow, numPanels, framesPerSecond, true );
}
else if ( patternMode == RAINBOW )
{
for ( int inx = 0; patternMode == RAINBOW && inx < numPanels; inx++ )
{
cycleRainbow( numPanels - 1 - inx, ledsPerRow, numPanels );
}
}
if ( patternMode == GRADIENT_PULSE )
{
// Cycle colors
// Start from black to red
if ( currentGradientPulseIteration == 0 )
{
for ( int inx = 0; inx < 16; inx++ )
{
longBufferPalette[inx] = CRGB::Black;
}
for ( int inx = 16; inx < 32; inx++ )
{
longBufferPalette[inx][0] = gradientArray[inx - 16];
longBufferPalette[inx][1] = 0;
longBufferPalette[inx][2] = 0;
}
for ( int inx = 0; patternMode == GRADIENT_PULSE && inx < numPanels; inx++ )
{
cycleBufferPalette( inx, ledsPerRow, numPanels );
}
}
else if ( currentGradientPulseIteration == 1 )
{
// Then red to yellow
for ( int inx = 0; inx < 16; inx++ )
{
longBufferPalette[inx][0] = gradientArray[inx];
longBufferPalette[inx][1] = 0;
longBufferPalette[inx][2] = 0;
}
for ( int inx = 16; inx < 32; inx++ )
{
longBufferPalette[inx][0] = gradientArray[inx - 16];
longBufferPalette[inx][1] = gradientArray[inx - 16];
longBufferPalette[inx][2] = 0;
}
for ( int inx = 0; patternMode == GRADIENT_PULSE && inx < numPanels; inx++ )
{
cycleBufferPalette( inx, ledsPerRow, numPanels );
}
}
else if ( currentGradientPulseIteration == 2 )
{
// Then yellow to green
for ( int inx = 0; inx < 16; inx++ )
{
longBufferPalette[inx][0] = gradientArray[inx];
longBufferPalette[inx][1] = gradientArray[inx];
longBufferPalette[inx][2] = 0;
}
for ( int inx = 16; inx < 32; inx++ )
{
longBufferPalette[inx][0] = 0;
longBufferPalette[inx][1] = gradientArray[inx - 16];
longBufferPalette[inx][2] = 0;
}
for ( int inx = 0; patternMode == GRADIENT_PULSE && inx < numPanels; inx++ )
{
cycleBufferPalette( inx, ledsPerRow, numPanels );
}
}
else if ( currentGradientPulseIteration == 3 )
{
// Then green to cyan
for ( int inx = 0; inx < 16; inx++ )
{
longBufferPalette[inx][0] = 0;
longBufferPalette[inx][1] = gradientArray[inx];
longBufferPalette[inx][2] = 0;
}
for ( int inx = 16; inx < 32; inx++ )
{
longBufferPalette[inx][0] = 0;
longBufferPalette[inx][1] = gradientArray[inx - 16];
longBufferPalette[inx][2] = gradientArray[inx - 16];
}
for ( int inx = 0; patternMode == GRADIENT_PULSE && inx < numPanels; inx++ )
{
cycleBufferPalette( inx, ledsPerRow, numPanels );
}
}
else if ( currentGradientPulseIteration == 4 )
{
// Then cyan to blue
for ( int inx = 0; inx < 16; inx++ )
{
longBufferPalette[inx][0] = 0;
longBufferPalette[inx][1] = gradientArray[inx];
longBufferPalette[inx][2] = gradientArray[inx];
}
for ( int inx = 16; inx < 32; inx++ )
{
longBufferPalette[inx][0] = 0;
longBufferPalette[inx][1] = 0;
longBufferPalette[inx][2] = gradientArray[inx - 16];
}
for ( int inx = 0; patternMode == GRADIENT_PULSE && inx < numPanels; inx++ )
{
cycleBufferPalette( inx, ledsPerRow, numPanels );
}
}
else if ( currentGradientPulseIteration == 5 )
{
// Then blue to magenta
for ( int inx = 0; inx < 16; inx++ )
{
longBufferPalette[inx][0] = 0;
longBufferPalette[inx][1] = 0;
longBufferPalette[inx][2] = gradientArray[inx];
}
for ( int inx = 16; inx < 32; inx++ )
{
longBufferPalette[inx][0] = gradientArray[inx - 16];
longBufferPalette[inx][1] = 0;
longBufferPalette[inx][2] = gradientArray[inx - 16];
}
for ( int inx = 0; patternMode == GRADIENT_PULSE && inx < numPanels; inx++ )
{
cycleBufferPalette( inx, ledsPerRow, numPanels );
}
}
else if ( currentGradientPulseIteration == 6 )
{
// Then magenta to red
for ( int inx = 0; inx < 16; inx++ )
{
longBufferPalette[inx][0] = gradientArray[inx];
longBufferPalette[inx][1] = 0;
longBufferPalette[inx][2] = gradientArray[inx];
}
for ( int inx = 16; inx < 32; inx++ )
{
longBufferPalette[inx][0] = gradientArray[inx - 16];
longBufferPalette[inx][1] = 0;
longBufferPalette[inx][2] = 0;
}
for ( int inx = 0; patternMode == GRADIENT_PULSE && inx < numPanels; inx++ )
{
cycleBufferPalette( inx, ledsPerRow, numPanels );
}
}
currentGradientPulseIteration++;
if ( currentGradientPulseIteration == 7 )
{
// Don't want to go back to 0 because that
// was just the initializer with a starting block of black.
currentGradientPulseIteration = 1;
}
}
}
void cycleBufferPalette( int pStartRowIndex, // Must be 0 to 16
int pLedsPerRow,
int pNumPanels
)
{
for ( int inx = 0; inx < pNumPanels; inx++ )
{
lightUpRow( longBufferPalette[inx + pStartRowIndex], inx, pLedsPerRow, pNumPanels );
}
}
void cycleBySinglePanel( CRGB pColor,
int pLedsPerRow,
int pNumPanels,
int pFramesPerSecond,
boolean pForward
)
{
for ( int inx = 0; inx < pNumPanels; inx++ )
{
if ( pForward )
{
lightUpRow( pColor, pNumPanels - 1 - inx, pLedsPerRow, pNumPanels );
delay( 1000 / pFramesPerSecond );
clearRow( pNumPanels - 1 - inx, pLedsPerRow, pNumPanels );
}
else
{
lightUpRow( pColor, inx, pLedsPerRow, pNumPanels );
delay( 1000 / pFramesPerSecond );
clearRow( inx, pLedsPerRow, pNumPanels );
}
}
}
void cycleFillPanel( CRGB pColor,
int pLedsPerRow,
int pNumPanels,
int pFramesPerSecond,
boolean pForward
)
{
for ( int inx = 0; inx < pNumPanels; inx++ )
{
if ( pForward )
{
lightUpRow( pColor, pNumPanels - 1 - inx, pLedsPerRow, pNumPanels );
delay( 1000 / pFramesPerSecond );
}
else
{
lightUpRow( pColor, inx, pLedsPerRow, pNumPanels );
delay( 1000 / pFramesPerSecond );
}
}
}
void cycleGradientTrail( int pStartRowIndex,
int pLedsPerRow,
int pNumPanels
)
{
int currentPanelIndex = pStartRowIndex;
for ( int inx = 0; inx < pNumPanels; inx++ )
{
currentPanelIndex = pStartRowIndex + inx;
if ( currentPanelIndex >= pNumPanels )
{
currentPanelIndex = currentPanelIndex - pNumPanels;
}
lightUpRow( gradientTrailPalette[inx], currentPanelIndex, pLedsPerRow, pNumPanels );
}
}
void cycleRainbow( int pStartRowIndex,
int pLedsPerRow,
int pNumPanels
)
{
int currentPanelIndex = pStartRowIndex;
for ( int inx = 0; inx < pNumPanels; inx++ )
{
currentPanelIndex = pStartRowIndex + inx;
if ( currentPanelIndex >= pNumPanels )
{
currentPanelIndex = currentPanelIndex - pNumPanels;
}
lightUpRow( rainbowPalette[inx], currentPanelIndex, pLedsPerRow, pNumPanels );
}
}
void lightUpRow( CRGB pColor,
int pRowIndex,
int pLedsPerRow,
int pNumPanels
)
{
int ledIndex = ( pNumPanels - 1 - pRowIndex ) * pLedsPerRow;
for ( int inx = ledIndex; inx < ledIndex + ledsPerRow; inx++ )
{
leds[inx] = pColor;
}
FastLED.show();
}
void clearRow( int pRowIndex,
int pLedsPerRow,
int pNumPanels
)
{
int ledIndex = ( pNumPanels - 1 - pRowIndex ) * pLedsPerRow;
for ( int inx = ledIndex; inx < ledIndex + ledsPerRow; inx++ )
{
leds[inx] = CRGB::Black;
}
FastLED.show();
}