This is the code:
#include <FastLED.h>
#define LED_PIN 10 //LED strip case top back.
#define NUM_LEDS 12
#define BRIGHTNESS 150
#define LED_TYPE WS2812B
#define COLOR_ORDER GRB
CRGB leds[NUM_LEDS];
#define UPDATES_PER_SECOND 50
int myLEDs[] = {0,1,2,3,4,5,6,7,8,9,10,11};
int x;
int i;
// This example shows how to cross-fade between different color palettes
// using the function nblendPaletteTowardPalette.
//
// The basic idea is that you always have a "current palette" that you're
// pulling colors from with ColorFromPalette, and you have a "target palette"
// which is the 'next' palette that you want to get to.
//
// After that, implementation is relatively simple: just periodically call
// nblendPaletteTowardPalette( currentPalette, targetPalette);
// If the current palette is not yet equal to the target palette, this
// function will make a few small changes to the current palette to make
// it slightly more like the target. Over time, the current palette will
// come to be equal to the target.
// There's no need to test the current and target for equality; it's safe
// to keep calling nblendPaletteTowardPalette even after current reaches target.
// For faster blending, call nblendPaletteTowardPalette twice per loop.
CRGBPalette16 currentPalette;
TBlendType currentBlending;
extern CRGBPalette16 myRedWhiteBluePalette;
extern const TProgmemPalette16 myRedWhiteBluePalette_p PROGMEM;
int paletteCounter;
void setup() {
delay( 3000 ); // power-up safety delay
FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
FastLED.setBrightness(BRIGHTNESS);
}
void loop(){
ChangePalettePeriodically();
// Crossfade current palette slowly toward the target palette
//
// Each time that nblendPaletteTowardPalette is called, small changes
// are made to currentPalette to bring it closer to matching targetPalette.
// You can control how many changes are made in each call:
// - the default of 24 is a good balance
// - meaningful values are 1-48. 1=veeeeeeeery slow, 48=quickest
// - "0" means do not change the currentPalette at all; freeze
uint8_t maxChanges = 0;
static uint8_t startIndex = 0;
startIndex = startIndex + 1; /* motion speed */
FillLEDsFromPaletteColors( startIndex);
FastLED.show();
FastLED.delay(1000 / UPDATES_PER_SECOND);
}
void FillLEDsFromPaletteColors( uint8_t colorIndex)
{
uint8_t brightness = 255;
for( int i = 0; i < 6; i++) {
leds[myLEDs[i] ] = x;
}
for (i = 0; i < 6; i++) {
leds[myLEDs[i]] = ColorFromPalette( currentPalette =RainbowColors_p, colorIndex + sin8(i*16), brightness); //change palette or colors.
colorIndex += 3;
}
for( int i = 6; i < 12 ; i++) {
leds[myLEDs[i] ] = x;
}
for (i = 6; i < 12; i++)
{
leds[myLEDs[i]] = ColorFromPalette( currentPalette =RainbowColors_p, colorIndex + sin8(i*16), brightness); //change palette or colors.
colorIndex += 3;
}
}
void ChangePalettePeriodically()
{
if( paletteCounter == 0) { fill_solid( currentPalette, 16, CRGB::Red); currentBlending = NOBLEND;}
if( paletteCounter == 1) { fill_solid( currentPalette, 16, CRGB::Crimson); currentBlending = NOBLEND;}
if( paletteCounter == 2) { fill_solid( currentPalette, 16, CRGB::Orange); currentBlending = NOBLEND;}
if( paletteCounter == 3) { fill_solid( currentPalette, 16, CRGB::DarkOrange); currentBlending = NOBLEND;}
if( paletteCounter == 4) { fill_solid( currentPalette, 16, CRGB::Yellow); currentBlending = NOBLEND;}
if( paletteCounter == 5) { fill_solid( currentPalette, 16, CRGB::Gold); currentBlending = NOBLEND;}
if( paletteCounter == 6) { fill_solid( currentPalette, 16, CRGB::Green); currentBlending = NOBLEND;}
if( paletteCounter == 7) { fill_solid( currentPalette, 16, CRGB::GreenYellow); currentBlending = NOBLEND;}
if( paletteCounter == 8) { fill_solid( currentPalette, 16, CRGB::Lime); currentBlending = NOBLEND;}
if( paletteCounter == 9) { fill_solid( currentPalette, 16, CRGB::Blue); currentBlending = NOBLEND;}
if( paletteCounter == 10) { fill_solid( currentPalette, 16, CRGB::Aqua); currentBlending = NOBLEND;}
if( paletteCounter == 11) { fill_solid( currentPalette, 16, CRGB::DarkTurquoise); currentBlending = NOBLEND;}
if( paletteCounter == 12) { fill_solid( currentPalette, 16, CRGB::Navy); currentBlending = NOBLEND;}
if( paletteCounter == 13) { fill_solid( currentPalette, 16, CRGB::Purple); currentBlending = NOBLEND;}
if( paletteCounter == 14) { fill_solid( currentPalette, 16, CRGB::Violet); currentBlending = NOBLEND;}
if( paletteCounter == 15) { fill_solid( currentPalette, 16, CRGB::DeepPink); currentBlending = NOBLEND;}
if( paletteCounter == 16) { fill_solid( currentPalette, 16, CRGB::LightCoral); currentBlending = NOBLEND;}
if( paletteCounter == 17) { fill_solid( currentPalette, 16, CRGB::White); currentBlending = NOBLEND;}
if( paletteCounter == 18) { fill_solid( currentPalette, 16, CRGB::BurlyWood); currentBlending = NOBLEND;}
if( paletteCounter == 19) { fill_solid( currentPalette, 16, CRGB::Thistle); currentBlending = NOBLEND;}
if( paletteCounter == 20) { fill_solid( currentPalette, 16, CRGB::White); currentBlending = NOBLEND;}
if( paletteCounter == 21) { currentPalette = RainbowColors_p; currentBlending = NOBLEND; }
if( paletteCounter == 22) { currentPalette = RainbowStripeColors_p; currentBlending = NOBLEND; }
if( paletteCounter == 23) { currentPalette = OceanColors_p; currentBlending = NOBLEND; }
if( paletteCounter == 24) { currentPalette = CloudColors_p; currentBlending = NOBLEND; }
if( paletteCounter == 25) { currentPalette = LavaColors_p; currentBlending = NOBLEND; }
if( paletteCounter == 26) { currentPalette = ForestColors_p; currentBlending = NOBLEND; }
if( paletteCounter == 27) { currentPalette = PartyColors_p; currentBlending = NOBLEND; }
if( paletteCounter == 28) { SetupPurpleAndGreenPalette(); currentBlending = LINEARBLEND; }
if( paletteCounter == 30) { SetupBlackAndWhiteStripedPalette(); currentBlending = NOBLEND; }
if( paletteCounter == 31) { SetupBlackAndWhiteStripedPalette(); currentBlending = LINEARBLEND; }
if( paletteCounter == 32) { currentPalette = myRedWhiteBluePalette_p; currentBlending = NOBLEND; }
if( paletteCounter == 33) { currentPalette = myRedWhiteBluePalette_p; currentBlending = LINEARBLEND; }
}
// This function sets up a palette of black and white stripes,
// using code. Since the palette is effectively an array of
// sixteen CRGB colors, the various fill_* functions can be used
// to set them up.
void SetupBlackAndWhiteStripedPalette()
{
// 'black out' all 16 palette entries...
fill_solid( currentPalette, 16, CRGB::Black);
// and set every fourth one to white.
currentPalette[0] = CRGB::White;
currentPalette[4] = CRGB::White;
currentPalette[8] = CRGB::White;
currentPalette[12] = CRGB::White;
}
// This function sets up a palette of purple and green stripes.
void SetupPurpleAndGreenPalette()
{
CRGB purple = CHSV( HUE_PURPLE, 255, 255);
CRGB green = CHSV( HUE_GREEN, 255, 255);
CRGB black = CRGB::Black;
currentPalette = CRGBPalette16(
green, green, black, black,
purple, purple, black, black,
green, green, black, black,
purple, purple, black, black );
}
// This example shows how to set up a static color palette
// which is stored in PROGMEM (flash), which is almost always more
// plentiful than RAM. A static PROGMEM palette like this
// takes up 64 bytes of flash.
const TProgmemPalette16 myRedWhiteBluePalette_p PROGMEM =
{
CRGB::Red,
CRGB::Gray, // 'white' is too bright compared to red and blue
CRGB::Blue,
CRGB::Black,
CRGB::Red,
CRGB::Gray,
CRGB::Blue,
CRGB::Black,
CRGB::Red,
CRGB::Red,
CRGB::Gray,
CRGB::Gray,
CRGB::Blue,
CRGB::Blue,
CRGB::Black,
CRGB::Black
};