/*"`^-.,___,.-^`"`^-.,___,.-^`"`^-.,___,.-^`"                                       "`^-.,___,.-^`"`^-.,___,.-^`"`^-.,___,.-^`"`^-.,___,.-^`* 
         U           _ U _         - U -        (_)(_)(_)(_)(_)| |_| |_ ___  ___           U           _ U _           U           - U -  
                      /|\           /|\         | || || || || || __|  _/ __|/ __|         /|\           /|\           /|\               
                                                | || || || || |\ |_\ |_\__ \\__ \
                                                |_||_||_||_||_| \__|\__|___/|___/

                        ___| |__  _ __(_)(_)(_)(_)(_)___| |_ _ __ ___   __ _  __ _  __ _  __ _ ___  ___  | || || |  
                       / __| '_ \| '__| || || || || / __| __| '_ ` _ \ / _`  / _`  / _`  / _` / __|/ __| | || || |  
                      | (__| | | | |  | || || || || \__ \ |_| | | | | | (_| | (_| | (_| | (_| \__ \\__ \ |_||_||_|
                       \___|_| |_|_|  |_||_||_||_||_|___/\__|_| |_| |_|\__,_|\__,_|\__,_|\__,_|___/|___/ (_)(_)(_)
                                        "`^-.,___,.-^`"`^-.,___,.-^`"`^-.,___,.-^`"`^-.,___,.-^`"`^-.,___,.-^`"
                            .-(_)              U           _ U _           U           _ U _         - U -
                           / _/                             /|\           /|\           /|\               
                        .-'   \
                       /       '.
                     ,-~--~-~-~-~-,
                    {__.._...__..._}            o,(o),
   o,888,o         /\##"  @  @  "##/\          ,88' `88,o
  ,(o)'(o),__     |(\`  , (__) ,  `/)|     __,88'o    `(o)
 ,88'   .8(_ \_____\_    '----'    _/_____/ _)o).       8'F
 (o)o  (___)\ \      '-.__    __.-'      / /(___)          AS
 88    (___)88o|          '--'          | 88(___)            TL            o                 o                         o 
o8'     (__)88,____/   FASTLEDFTW   \___o,88(__)                ED!((Elf Art by Joan Stark)... found On the interwebs - search for aasci art!) 
_____________`(o),/__________________\_,(o)`_________________________o___________________o__________o____________o____________________________
              o`88,                  ,88'    
                  `(o),       o    ,(o)'o          & THE ELVES HAVE BEEN BUSY DECORATING ALL YOUR CODES....... UH-OH!       
                    o`88,_\(o)/_,88` 
                            
*/    
//^-.,___,.-^`"`^-.,___,.-^`"`^-.,___,.-^`"`^-.,___,.-^`"`^-.,___,.-^`"`^-.,___,.-^`"`^-.,___,.-^`"`^-.,___,.-^`"`^-.,___,.-^`"`^-.,___,.-^// 
//   _ U _         - U -         - U -         - U -           U           _ U _           U           _ U _         - U -         - U -    
//    /|\            |                          /|\                         /|\           /|\           /|\                          |   
//
//                                                     ANOTHER YEAR ANOTHER DEMO REEL!          
//                                                         CHRISTMAS EDITION 2020                 
//                                                           
//                                                              DEMO SKETCH                  
//                                                        (Running on NanoV3 328p)
//                                (Compatible with the smaller 328p Arduinos - UNO, NANO, PRO MINI, PRO MICRO)              
//                          & Runs best (visually) on WS2811 8mm String lights (For your Tree or as string lights!)                                     
//
//
//,.-^`"`^-.,___,.-^`"`^-.,___,.-^`"`^-.,___,.-^`"`^-.,___,.-^`"`^-.,___,.-^`"`^-.,___,.-^`"`^-.,___,.-^`"`^-.,___,.-^`"`^-.,___,.-^`"`^-.,// 
//          - U -         - U -         - U -           U           _ U _           U           _ U _         - U -         - U -    
//            |                          /|\                         /|\           /|\           /|\                          |   


//==========================================================================================================================================
//================== FastLED definitions

#include <FastLED.h>
#define DATA_PIN               3        // Which pin on the Arduino is connected to the leds?

//==========================================================================================================================================
//=================== Fairy style lights 8mm pixels
//------WS2811

#define LED_TYPE               WS2812B
#define NUM_LEDS               241      // How many leds are attached to the Arduino?
#define VOLTS                  5
#define MAX_MA                 15000    // LIMITER - 500 is a safe start!- Can go up to 2000ma(safely)-(8mmPixel) 
                                         //(if you have sufficiant Amps to each string)
                                         // set to 1300ma MAX if sharing power for two 5v strings (Before color washout and flicker occurs)
#define COLOR_CORRECTION       Typical8mmPixel

//==========================================================================================================================================
//=================== Flat strip lights
//------WS2182B

//#define LED_TYPE              WS2812B
//#define NUM_LEDS              144     // How many leds are attached to the Arduino?
//#define VOLTS                 5
//#define MAX_MA                500
//#define COLOR_CORRECTION      TypicalLEDStrip

//==========================================================================================================================================
//------TM1809/TM1812  

//#define LED_TYPE              TM1809  // MUST LINK (ARDUINO GND)--TO--(STRIP GND(-)) & (DATA)--TO--(DATA)
//#define NUM_LEDS              150      // How many leds are attached to the Arduino?
//#define VOLTS                 5
//#define MAX_MA                500
//#define COLOR_CORRECTION      TypicalLEDStrip

//==========================================================================================================================================
//=================== Led color order

//IF YOUR LED COLORS ARE IN THE WRONG ORDER GHANGE HERE:

//#define LED_COLOR_ORDER           RGB
#define LED_COLOR_ORDER           GRB 
//#define LED_COLOR_ORDER           RBG
//#define LED_COLOR_ORDER           GBR 
//#define LED_COLOR_ORDER           BRG 
//#define LED_COLOR_ORDER           BGR 

//==========================================================================================================================================
//======================== Variables for Glitter / Sparkle / SparkleBomb (These are set at comfortable levels but can be changed if needed)
 
#define GLITTER_AMOUNT        60 // white glitter slower paced than sparkle
                                 //(10-90) (60=nice pace glitter)(90= too much glitter!!) 
                                 //(120= !!!SHOULD COME WITH A HEALTH WARNING OR SOMETHING?!!)

#define SPARKLE_AMOUNT        30 // white and yellow sparkles  
                                 // (30-70)(30= nice pace sparkles)(70= too many sparkles!!) 
                                 //(100= !!!SHOULD COME WITH A HEALTH WARNING OR SOMETHING?!!)

#define SPARKLEBOMB_AMOUNT    1  // Extra white and yellow sparkles (increment by 1)
                                 //(1-6)(1= nice pace sparkles)(6= too many sparkles!!) 
                                 //(10= !!!SHOULD COME WITH A HEALTH WARNING OR SOMETHING?!!)

#define FADEOUT_SPEED         40 // speed of glitter and sparkle fade out (10=slow)(100=fast)

//==========================================================================================================================================
//======================= Variables for later patterns (not for changing)

CRGB leds[NUM_LEDS];
byte ledh[NUM_LEDS];       //used for sparkle
byte ledb[NUM_LEDS];       //used for sparkle

byte state      = 1;   
int  index      = 0;       //-LED INDEX (0 to LED_COUNT-1)

byte thisbright = 255;     // for later patterns (random burst, random march, rgb prop, candycane etc...)
byte thissat    = 255;     // for later patterns (random burst, random march, rgb prop, candycane etc...)
int  thisdelay  = 50;      // for later patterns (random burst, random march, rgb prop, candycane etc...)
byte thisstep   = 10;      // for later patterns (random burst, random march, rgb prop, candycane etc...)
byte thishue    = 0;       // for later patterns (random burst, random march, rgb prop, candycane etc...)
byte thathue    = 0;       // for later patterns (random burst, random march, rgb prop, candycane etc...)

int sparkTest   = 0;       // sparkTest:   variable used in the "sparkle & addPixieDust" sequence (a poor mans pixie dust!) 

uint16_t ledsData[NUM_LEDS][4];//For colorTwinkle array to store color data and an extra value
uint16_t pick;                 //For colorTwinkles  stores a temporary pixel number

//==========================================================================================================================================
//======================= Variables for TwinkleFox and DemoPatternList 

#define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0]))   //for DemoPatternList

#define SECONDS_PER_PATTERN  30            // How often to change DemoPatternList
#define SECONDS_PER_PALETTE  30            // How often to change twinklefox color palettes.(USED FOR TWINKLEFOX TIMING) 

#define COLOR_MATCH                        //!! use this to "group similar" colors ... 
                                           // << use this before #define to turn off (like this) //#define COLOR_MATCH 

CRGBPalette16 gCurrentPalette;             // for TwinkleFox
CRGBPalette16 gTargetPalette;              // for TwinkleFox

uint8_t current_loop           = 1;        // use 1 for DEMO MODE and 2 for a single pattern (TwinkleFOX)(can be changed in loop)      
uint8_t GLOBAL_BRIGHTNESS      = 255;      // BRIGHTNESS CAN BE CHANGED HERE. 255 = MAX (rolls over to 0 if you go higher)
uint8_t fps                    = 60;       // Animation/Pattern speed (frames per second) 60 = Normal

uint8_t gCurrentPatternNumber  = 0;        // Index number of which pattern is current (for demoPatternList)
uint8_t gHue                   = 0;        // rotating "base color" used by many of the patterns
uint8_t ghue                   = 0;        // slower rotating "base color" used by many of the patterns

//==========================================================================================================================================
//==========================================================================================================================================
//^-.,___,.-^`"`^-.,___,.-^`"`^-.,___,.-^`"`^-.,___,.-^`"`^-.,___,.-^`"`^-.,___,.-^`"`^-.,___,.-^`"`^-.,___,.-^`"`^-.,___,.-^`"`^-.,___,.-^// 
//   _ U _         - U -         - U -         - U -           U           _ U _           U           _ U _         - U -         - U -    
//    /|\            |                          /|\                         /|\           /|\           /|\                          |   
//
//==========================================================================================================================================

void setup(){

//========================= Initialize LEDS              
  FastLED.setMaxPowerInVoltsAndMilliamps( VOLTS, MAX_MA);
  FastLED.addLeds<LED_TYPE,DATA_PIN,LED_COLOR_ORDER>(leds, NUM_LEDS).setCorrection( COLOR_CORRECTION );
  FastLED.setBrightness(GLOBAL_BRIGHTNESS);
  fadeToBlackBy( leds, NUM_LEDS,255);
  FastLED.clear();
  
 // for TwinkleFox
  chooseNextColorPalette(gTargetPalette);    // chooses next color palette to blend towards.
}

//==========================================================================================================================================
//========================= DEMO Pattern List

// List of patterns to cycle through. (all found in other tabs)
// GLITTER FOR ALL!! AAHHAHAHA!!! - change amount at top ^^ (...if you must!)

typedef void (*DemoPatternList[])();
DemoPatternList gPatterns = { 
 
#if defined(COLOR_MATCH)            //change at top if not wanted.

//------------------------------ (COLOR_MATCH)

  fireStarter,                      // Yellow
  cometEffect,                      // Yellow
  YellowRipple,
  paletteFairyGold,
  YellowWhiteRipple,
  YellowRedRipple,
  paletteFairyLight,
  CandleTree4,                      // Yellow
  paletteCandle,
  random_march,
  YellowGreenWhiteDot,
  GreenGreenWhiteDot,
  Glimmer,                          // Green
  GreenRipple,
  paletteGreenPurple,
  paletteforest,
  paletteGreenWhite,
  GreenWhiteRipple,
  paletteGreenWhiteStripes,
  matrix4,                          // Light Green
  GreenBlueWhiteDot,
  cometChaserYELLOW_GREEN,
  CandleTree2,                      // Green
  matrix5,                          // Light Green
  paletteholly,                     // Green
  paletteRedGreenWhite,
  paletteRedGoldGreen,
  matrix1,                          // Green
  RedGreenWhiteDot,
  matrix3,                          // Red
  paletteRedGreenAlt,
  paletteRedGreenAltFlash,
  paletteTraditionalRedGreen,        //(put after desired color for alt fill-in)
  paletteTraditionalRedGreenReverse, //(put after desired color for alt fill-in)
  paletteTraditionalRedGreenWhite,
  RedWhiteRipple,
  candycane,                        // Red/White
  paletteRedWhiteStripes,           // Red/White
  palettelava,                      // Red/White
  RedRipple,
  CandleTree1,                      // Red
  matrix2,                          // Blue
  BlueRipple,
  CandleTree3,                      // Blue
  GreenBlueRipple,
  paletteocean,                     // Blue
  palettecloud,                     // Blue/White
  BlueWhiteRipple,
  paletteIce,
  paletteIce2,
  paletteSnow,
  paletteBlueWhite,
  IridescentSparkle,    
  cometChaserAQUA,
  TurquoiseRipple,
  TurquoiseWhiteRipple,
  TurquoisePurpleRipple,
  matrix6,
  PurpleWhiteRipple,                // Purple
  PurpleRipple,                     // Purple
  rgb_propeller,                     // R,G,B
  paletteRetroC9,                    // R,G,B,O
  random_burst,
  sinelon2,                          // Rainbow
  sinelon,                           // Rainbow
  cometEffectSinelonGHUE_SLOW_RAINBOW,
  cometChaserRAINBOW,
  pixieDustBackground1,
  fireStarter_YELLOW_GREEN,  
  fireStarter_RAINBOW_PULSE_SLOW,
  fireStarterGHUE_RAINBOW,
  rainbow_pulse,                     // Rainbow
  rainbow_pulse2,                    // Rainbow
  paletterainbowstripe,              // Rainbow
  bighalfrainbow,                    // Rainbow
  paletteparty,                      // Mixed
  paletterainbowstripe2,             // Rainbow
  bigrainbow,                        // Rainbow
  paletterainbowstripe3,             // Rainbow
  rainbow3,                          // Rainbow
  rainbow,                           // Rainbow
  miniRainbow,                       // Rainbow
  rainbowDots,                       // Rainbow
  TwinkleFox,
  meteorRain,                       // White
#endif


#if !defined(COLOR_MATCH)   
//------------------------------ (ORIGINAL ORDER)

  CandleTree1,
  CandleTree2,
  CandleTree3,
  CandleTree4,
  RedGreenWhiteDot,
  GreenGreenWhiteDot,
  GreenBlueWhiteDot,
  YellowGreenWhiteDot,
  cometEffectSinelonGHUE_SLOW_RAINBOW,
  Glimmer,
  GreenBlueRipple,
  TurquoisePurpleRipple,
  YellowRedRipple,
  RedWhiteRipple,
  GreenWhiteRipple,
  BlueWhiteRipple,
  PurpleWhiteRipple,
  TurquoiseWhiteRipple,
  YellowWhiteRipple,
  RedRipple,
  GreenRipple,
  BlueRipple,
  PurpleRipple,
  TurquoiseRipple,
  YellowRipple,
  cometEffect,
  cometChaserYELLOW_GREEN,
  cometChaserAQUA,
  cometChaserRAINBOW,
  fireStarter,
  fireStarter_YELLOW_GREEN,
  pixieDustBackground1,
  fireStarter_RAINBOW_PULSE_SLOW,
  fireStarterGHUE_RAINBOW,
  paletteRedWhiteStripes,
  paletteRedGreenAlt,
  paletteRedGreenAltFlash,
  paletteholly,
  paletteocean,
  palettecloud,
  palettelava,
  paletteparty,
  paletteRetroC9,
  rgb_propeller,
  candycane,
  IridescentSparkle,
  sinelon2,
  sinelon,
  rainbow_pulse,
  rainbow_pulse2,
  paletterainbowstripe,
  paletterainbowstripe2,
  paletterainbowstripe3,
  bighalfrainbow,
  bigrainbow,
  rainbow,
  miniRainbow,
  rainbowDots,
  rainbow3,
  rainbow_loop,
  paletteBlueWhite,
  paletteGreenWhite,
  paletteGreenWhiteStripes,
  paletteforest,
  paletteSnow,
  paletteIce2,
  paletteIce,
  paletteTraditionalRedGreen,        //(put after desired color for alt fill-in)
  paletteTraditionalRedGreenReverse, //(put after desired color for alt fill-in)
  paletteTraditionalRedGreenWhite,
  paletteRedGreenWhite,
  paletteGreenPurple,
  paletteRedGoldGreen,
  paletteFairyGold,
  paletteFairyLight,
  paletteCandle,
  matrix1,
  matrix2,
  matrix3,
  matrix4,
  matrix5,
  matrix6,
  random_march,
  random_burst,
  TwinkleFox,
  meteorRain,
#endif
};             
                // Note: TwinkleFox will NOT run its full timing here (SECONDS_PER_PALETTE) 
                // as (SECONDS_PER_PATTERN) is in control of the looptime.
                // the effect still looks nice as a random palette happens each time its called from here<<<
                // (SECONDS_PER_PALETTE) works normal if "TwinkleFox();" is on a seperate button as its own loop.-
                // or if the overall (SECONDS_PER_PATTERN) is longer than:  TwinkleFox list of palettes x (SECONDS_PER_PALETTE)

// NOTE: to use the following cut or copy them into the list you are using above (COLOR_MATCH or non ORIGINAL_ORDER list)
// also you could comment out all of the patterns you dont like in the lists above to make a shorter list maybe?.

//SPARE PATTERNS:

//colortwinkles,// this one will run from twinklefox timings (EVERY_N_MILLIS) & palette list (ActivePaletteList)
//solidGreenTwinkles,         //Nice but a bit too sparcely lit
//solidGreen2Twinkles,        // same
//solidGreen3Twinkles,        // same
//IridescentTwinkles,         // same
//classicTwinkles,            // same
//cloudTwinkles,              // same
//rainbowTwinkles,            // same
//snowTwinkles,               // same
//incandescentTwinkles,       //Nice but a bit too sparcely lit

//chaserfadeRedGreenWhiteDot, // old one 
//colorwipeRedGreen,          // old one 
//SilentNightRiderRedGreen,   // old one 
//NewKITT_ALL,                // old one 

// NOTE: you can put addSparkle(); or addSparklebomb(); or addGreenSparkle(); instead of addGlitter();

//justGlitter,                // same(These were made as an example to show the different types of glitter)
//justSparkle,                // same(These were made as an example to show the different types of glitter)
//justSparkleOldSchool1,      // same(These were made as an example to show the different types of glitter)
//justSparkleOldSchool2,      // same(These were made as an example to show the different types of glitter)
//GreenSparkle,               // same(These were made as an example to show the different types of glitter)
//RedSparkle,                 // same(These were made as an example to show the different types of glitter)
//BlueSparkle,                // same(These were made as an example to show the different types of glitter)
//rgbSparkle,                 // a bit too flashy for room decorations fine for ornaments (^"""""""""""""""^)

//confetti,                   // a bit too flashy for room decorations fine for ornaments
//juggle,                     // Too quick for string lights that are at close proximity to you // better for strips. 
//sinelonWhite,               // ok but too Bland

//CandleON,     //messes with Brightness and color temp on exit... to be worked on for 2021!
//BlacklightON, //messes with Brightness and color temp on exit... to be worked on for 2021!

// NOTE: not ALL of these will fit on a 328p so i have only selected the best looking ones, 
// If you have a larger memory board you could add ALL of these back into the demolist.

//==========================================================================================================================================
//,.-^`"`^-.,___,.-^`"`^-.,___,.-^`"`^-.,___,.-^`"`^-.,___,.-^`"`^-.,___,.-^`"`^-.,___,.-^`"`^-.,___,.-^`"`^-.,___,.-^`"`^-.,___,.-^`"`^-.,// 
//          - U -         - U -         - U -           U           _ U _           U           _ U _         - U -         - U -    
//            |                          /|\                         /|\           /|\           /|\                          |   
//
//==========================================================================================================================================

// ------------------------------ Loop 

void loop(){                
  
  EVERY_N_MILLISECONDS( 1 ) { gHue++; }                                        // FAST - cycle the "base color" through the rainbow
  EVERY_N_SECONDS( 1 ) { ghue++; }                                             // SLOW - cycle the "base color" through the rainbow
  EVERY_N_SECONDS( SECONDS_PER_PALETTE ) { chooseNextColorPalette( gTargetPalette );}             //  change palettes periodically
  EVERY_N_MILLISECONDS( 20 ) { nblendPaletteTowardPalette( gCurrentPalette, gTargetPalette, 12);} // blend current palette to next palette


switch (current_loop){

    case 1:
    {      
     gPatterns[gCurrentPatternNumber](); // Call the current pattern function once, updating the 'leds' array
     EVERY_N_SECONDS( SECONDS_PER_PATTERN ) { nextPattern();}  
      break;
    }

    case 2:
    { 
      TwinkleFox();                      // can be changed to any pattern you want... or maybe add more cases based off this example?
      break;
    }
}
  // send the 'leds' array out to the actual LED strip
  FastLED.show();  
  // insert a delay to keep the framerate modest
  FastLED.delay(1000/fps);
}

// Loopy stuff  >> ENDS HERE <<

//==========================================================================================================================================
//^-.,___,.-^`"`^-.,___,.-^`"`^-.,___,.-^`"`^-.,___,.-^`"`^-.,___,.-^`"`^-.,___,.-^`"`^-.,___,.-^`"`^-.,___,.-^`"`^-.,___,.-^`"`^-.,___,.-^// 
//   _ U _         - U -         - U -         - U -           U           _ U _           U           _ U _         - U -         - U -    
//    /|\            |                          /|\                         /|\           /|\           /|\                          |   

//==========================================================================================================================================
//============================= Choose next pattern from DemoPatternList

void nextPattern()
{  
  
  // add one to the current pattern number, and wrap around to top of pattern list if we get to the end.
  gCurrentPatternNumber = (gCurrentPatternNumber + 1) % ARRAY_SIZE( gPatterns);
 
}

//FIN*
//==========================================================================================================================================
//^-.,___,.-^`"`^-.,___,.-^`"`^-.,___,.-^`"`^-.,___,.-^`"`^-.,___,.-^`"`^-.,___,.-^`"`^-.,___,.-^`"`^-.,___,.-^`"`^-.,___,.-^`"`^-.,___,.-^// 
//   _ U _         - U -         - U -         - U -           U           _ U _           U           _ U _         - U -         - U -    
//    /|\            |                          /|\                         /|\           /|\           /|\                          |   
//
//==========================================================================================================================================

/*
Art by Shanaka Dias

    |,\/,| |[_' |[_]) |[_]) \\//
    ||\/|| |[_, ||'\, ||'\,  ||

            ___ __ __ ____  __  __  ____  _  _    __    __
           // ' |[_]| |[_]) || ((_' '||' |,\/,|  //\\  ((_'
           \\_, |[']| ||'\, || ,_))  ||  ||\/|| //``\\ ,_))
                                                               

                                         ,;7,
                                       _ ||:|,
                     _,---,_           )\'  '|
                   .'_.-.,_ '.         ',')  j
                  /,'   ___}  \        _/   /
      .,         ,1  .''  =\ _.''.   ,`';_ |
    .'  \        (.'T ~, (' ) ',.'  /     ';',
    \   .\(\O/)_. \ (    _Z-'`>--, .'',      ;
     \  |   I  _|._>;--'`,-j-'    ;    ',  .'
    __\_|   _.'.-7 ) `'-' "       (      ;'
  .'.'_.'|.' .'   \ ',_           .'\   /
  | |  |.'  /      \   \          l  \ /
  | _.-'   /        '. ('._   _ ,.'   \i
,--' ---' / k  _.-,.-|__L, '-' ' ()    ;
 '._     (   ';   (    _-}             |
  / '     \   ;    ',.__;         ()   /
 /         |   ;    ; ___._._____.: :-j
|           \,__',-' ____: :_____.: :-\
|               F :   .  ' '        ,  L
',             J  |   ;             j  |
  \            |  |    L            |  J
   ;         .-F  |    ;           J    L
    \___,---' J'--:    j,---,___   |_   |
              |   |'--' L       '--| '-'|
               '.,L     |----.__   j.__.'
                | '----'   |,   '-'  }
                j         / ('-----';
               { "---'--;'  }       |
               |        |   '.----,.'
               ',.__.__.'    |=, _/
                |     /      |    '.
                |'= -x       L___   '--,
                L   __\          '-----'
                 '.____)
*/
   
  //   Thankyou Daniel Garcia for the gift that keeps on giving ...Peace Love and Light Brother. 



//                                      ----------------                                                 //
    /////////////////////////////////     ALL PALETTES    ////////////////////////////////////////////
//                                      ----------------                                                 //
//Here are TwinkleFox palette colors by Mark Kriegsman, Custom palettes & built in FastLED palette colors

//(I TOLD THE ELVES NOT TO DECORATE HERE) - (FOR EASY COPYING TO YOUR OWN SKETCHES)
 //======================================================================

// For Green Ripple
const TProgmemRGBPalette16 RippleGreen_p FL_PROGMEM =
{  CRGB::Green,CRGB::Green,CRGB::Black, CRGB::Black,
   CRGB::Black, CRGB::Green, CRGB::Black, CRGB::Black, 
   CRGB::Green,CRGB::Black, CRGB::Green, CRGB::Black, 
   CRGB::Black, CRGB::Black, CRGB::Green, CRGB::Black };

//======================================================================

// For Red Ripple
const TProgmemRGBPalette16 RippleRed_p FL_PROGMEM =
{  CRGB::Red,CRGB::Red,CRGB::Black, CRGB::Black,
   CRGB::Black, CRGB::Red, CRGB::Black, CRGB::Black, 
   CRGB::Red,CRGB::Black, CRGB::Red, CRGB::Black, 
   CRGB::Black, CRGB::Black, CRGB::Red, CRGB::Black };

//======================================================================

// For Blue Ripple
const TProgmemRGBPalette16 RippleBlue_p FL_PROGMEM =
{  CRGB::Blue,CRGB::Blue,CRGB::Black, CRGB::Black,
   CRGB::Black, CRGB::Blue, CRGB::Black, CRGB::Black, 
   CRGB::Blue,CRGB::Black, CRGB::Blue, CRGB::Black, 
   CRGB::Black, CRGB::Black, CRGB::Blue, CRGB::Black };

//======================================================================

// For Yellow Ripple
const TProgmemRGBPalette16 RippleYellow_p FL_PROGMEM =
{  CRGB::Yellow,CRGB::Yellow,CRGB::Black, CRGB::Black,
   CRGB::Black, CRGB::Yellow, CRGB::Black, CRGB::Black, 
   CRGB::Yellow,CRGB::Black, CRGB::Yellow, CRGB::Black, 
   CRGB::Black, CRGB::Black, CRGB::Yellow, CRGB::Black };

//======================================================================

// For Purple Ripple
const TProgmemRGBPalette16 RipplePurple_p FL_PROGMEM =
{  CRGB::Purple,CRGB::Purple,CRGB::Black, CRGB::Black,
   CRGB::Black, CRGB::Purple, CRGB::Black, CRGB::Black, 
   CRGB::Purple,CRGB::Black, CRGB::Purple, CRGB::Black, 
   CRGB::Black, CRGB::Black, CRGB::Purple, CRGB::Black };

//======================================================================

// For Turquoise Ripple
const TProgmemRGBPalette16 RippleTurquoise_p FL_PROGMEM =
{  CRGB::Cyan,  CRGB::Cyan,  CRGB::Black, CRGB::Black,
   CRGB::Black, CRGB::Cyan,  CRGB::Black, CRGB::Black, 
   CRGB::Cyan,  CRGB::Black, CRGB::Cyan,  CRGB::Black, 
   CRGB::Black, CRGB::Black, CRGB::Cyan,  CRGB::Black };

//======================================================================

// For White Ripple
const TProgmemRGBPalette16 RippleWhite_p FL_PROGMEM =
{  CRGB::White,CRGB::White,CRGB::Black, CRGB::Black,
   CRGB::Black, CRGB::White, CRGB::Black, CRGB::Black, 
   CRGB::White,CRGB::Black, CRGB::White, CRGB::Black, 
   CRGB::Black, CRGB::Black, CRGB::White, CRGB::Black };

//======================================================================

// A mostly red palette with green accents and white trim.
const TProgmemRGBPalette16 RedGreenWhite_p FL_PROGMEM =
{  CRGB::White, CRGB::White, CRGB::Red, CRGB::Red, 
   CRGB::Green, CRGB::Green, CRGB::Green, CRGB::Green, 
   CRGB::Red, CRGB::Red, CRGB::Red, CRGB::Green,
   CRGB::Green, CRGB::Green, CRGB::Green, CRGB::Green };

//======================================================================

// A mostly (dark) green palette with red berries.
#define Holly_Green 0x00580c
#define Holly_Red   0xB00402
const TProgmemRGBPalette16 Holly_p FL_PROGMEM =
{  Holly_Green, Holly_Green, Holly_Green, Holly_Green, 
   Holly_Green, Holly_Green, Holly_Green, Holly_Green, 
   Holly_Green, Holly_Green, Holly_Green, Holly_Green, 
   Holly_Green, Holly_Green, Holly_Green, Holly_Red 
};

//======================================================================

// A red and white striped palette
const TProgmemRGBPalette16 RedWhiteStripes_p FL_PROGMEM =
{  CRGB::White, CRGB::White, CRGB::White, CRGB::White,
   CRGB::Red,  CRGB::Red,  CRGB::Red,  CRGB::Red, 
   CRGB::White, CRGB::White, CRGB::White, CRGB::White,
   CRGB::Red,  CRGB::Red,  CRGB::Red,  CRGB::Red };

//======================================================================

// A green and Purple palette
const TProgmemRGBPalette16 GreenPurple_p FL_PROGMEM =
{  CRGB::Lime,      CRGB::Lime,      CRGB::DarkGreen, CRGB::Purple,
   CRGB::LightGreen,CRGB::LawnGreen, CRGB::DarkGreen, CRGB::Purple,
   CRGB::Lime,      CRGB::Lime,      CRGB::DarkGreen, CRGB::Purple,
   CRGB::LightGreen,CRGB::LawnGreen, CRGB::DarkGreen, CRGB::Purple,};

//====================================================================== 

// A red, gold, green, white palette
const TProgmemRGBPalette16 RedGoldGreen_p FL_PROGMEM =
{  CRGB::Red,  CRGB::Gold,  CRGB::Green,  CRGB::Silver,
   CRGB::Red,  CRGB::Gold,  CRGB::Green,  CRGB::White,
   CRGB::Red,  CRGB::Gold,  CRGB::Green,  CRGB::Silver,
   CRGB::Red,  CRGB::Gold,  CRGB::Green,  CRGB::White};

//======================================================================

// A Yellow, gold, Silver, white palette
const TProgmemRGBPalette16 FairyGold_p FL_PROGMEM =
{  CRGB::Gold, CRGB::Gold, CRGB::FairyLightNCC, CRGB::Silver,
   CRGB::Gold, CRGB::FairyLight, CRGB::Gold, CRGB::Grey,
   CRGB::FairyLightNCC, CRGB::Gold, CRGB::FairyLightNCC, CRGB::Silver,
   CRGB::Gold, CRGB::FairyLight, CRGB::Gold, CRGB::Grey,};

//======================================================================  

// A green and white striped palette
// "CRGB::Silver" is used as white to keep the brightness more uniform.
const TProgmemRGBPalette16 GreenWhiteStripes_p FL_PROGMEM =
{  CRGB::Silver, CRGB::Silver, CRGB::Silver, CRGB::Silver,
   CRGB::Green,CRGB::Green,CRGB::Green,CRGB::Green, 
   CRGB::Silver, CRGB::Silver, CRGB::Silver, CRGB::Silver,
   CRGB::Green,CRGB::Green,CRGB::Green,CRGB::Green };

//======================================================================  

// A mostly light blue palette with white accents.
const TProgmemRGBPalette16 BlueWhite_p FL_PROGMEM =
{  CRGB::LightBlue, CRGB::LightBlue, CRGB::LightBlue, CRGB::LightBlue, 
   CRGB::LightBlue, CRGB::LightBlue, CRGB::LightBlue, CRGB::LightBlue,  
   CRGB::LightBlue, CRGB::Gray, CRGB::White, CRGB::Silver, 
   CRGB::CornflowerBlue, CRGB::Gray, CRGB::White, CRGB::Silver };

//======================================================================

// A mostly light green palette with white accents.
const TProgmemRGBPalette16 GreenWhite_p FL_PROGMEM =
{  CRGB::LightGreen, CRGB::LightGreen, CRGB::LightGreen, CRGB::LightGreen, 
   CRGB::LightGreen, CRGB::LightGreen, CRGB::LightGreen, CRGB::LightGreen, 
   CRGB::LightGreen, CRGB::Gray, CRGB::White, CRGB::Silver, 
   CRGB::Lime, CRGB::Gray, CRGB::White, CRGB::Silver };

//======================================================================

// A pure "fairy light" palette with some brightness variations
#define HALFFAIRY ((CRGB::FairyLight & 0xFEFEFE) / 2)
#define QUARTERFAIRY ((CRGB::FairyLight & 0xFCFCFC) / 4)
const TProgmemRGBPalette16 FairyLight_p FL_PROGMEM =
{  CRGB::FairyLightNCC, CRGB::FairyLightNCC, HALFFAIRY, CRGB::FairyLightNCC, 
   CRGB::FairyLightNCC, CRGB::FairyLightNCC, CRGB::FairyLightNCC, CRGB::FairyLightNCC,  
   CRGB::FairyLightNCC, HALFFAIRY, CRGB::FairyLightNCC, CRGB::FairyLightNCC,  
   QUARTERFAIRY , CRGB::FairyLightNCC, CRGB::FairyLightNCC, CRGB::FairyLightNCC };

//======================================================================

// A palette of soft snowflakes with the occasional bright one
const TProgmemRGBPalette16 Snow_p FL_PROGMEM =
{  0x304048, 0x304048, 0x304048, 0x304048,
   0x304048, 0x304048, 0x304048, 0x304048,
   0x304048, 0x304048, 0x304048, 0x304048,
   0x304048, 0x304048, 0x304048, 0xE0F0FF };

//======================================================================

// A palette reminiscent of large 'old-school' C9-size tree lights
// in the five classic colors: red, orange, green, blue, and white.
#define C9_Red    0xB80400
#define C9_Orange 0x902C02
#define C9_Green  0x046002
#define C9_Blue   0x070758
#define C9_White  0x606820
const TProgmemRGBPalette16 RetroC9_p FL_PROGMEM =
{  C9_Red,    C9_Red,    C9_Red,    C9_Red,
   C9_Orange, C9_Orange, C9_Orange, C9_Orange, 
   C9_Green,  C9_Green,  C9_Green,  C9_Green,
   C9_Blue,   C9_Blue,   C9_Blue,
   C9_White
};

//======================================================================

// A cold, icy pale blue palette
#define Ice_Blue1 0x0C1040
#define Ice_Blue2 0x182080
#define Ice_Blue3 0x5080C0
const TProgmemRGBPalette16 Ice_p FL_PROGMEM =
{
  Ice_Blue3, Ice_Blue3, Ice_Blue3, Ice_Blue3,
  Ice_Blue3, 0x304048, Ice_Blue3, Ice_Blue3,
  Ice_Blue3, Ice_Blue3, Ice_Blue3, Ice_Blue3,
  Ice_Blue1, Ice_Blue3, Ice_Blue3, Ice_Blue3
};
//======================================================================

// A green & pale blue palette
#define Ice_Blue1 0x0C1040
#define Ice_Blue2 0x182080
#define Ice_Blue3 0x5080C0
#define Holly_Green 0x00580c
const TProgmemRGBPalette16 Ice2_p FL_PROGMEM =
{
  Holly_Green, Holly_Green, Ice_Blue3, Holly_Green,
  Ice_Blue3, Ice_Blue3, Ice_Blue3, Ice_Blue3,
  Ice_Blue3, Ice_Blue3, Ice_Blue3, Ice_Blue3,
  Ice_Blue3, Ice_Blue3, Ice_Blue3, Ice_Blue3
};
//======================================================================

// icy BlackLight 
#define BlackLight 0xA700FF
const TProgmemRGBPalette16 PALBlacklight_p FL_PROGMEM =
{
  0x304048, BlackLight, BlackLight, BlackLight,
  BlackLight, BlackLight, BlackLight, BlackLight,
  BlackLight, BlackLight, BlackLight, BlackLight,
  BlackLight, BlackLight, BlackLight, BlackLight
};
//======================================================================

// A Warm Candle (or Bonfire!) 
#define Candleflame 0xFF9329

const TProgmemRGBPalette16 PALCandle_p FL_PROGMEM =
{
  CRGB::FairyLightNCC,CRGB::FairyLightNCC,CRGB::White,Candleflame,
  Candleflame,Candleflame,Candleflame,CRGB::FairyLightNCC,
  Candleflame,Candleflame,Candleflame,Candleflame,
  Candleflame,Candleflame,Candleflame,Candleflame,
};

//======================================================================

// A traditional palette with red and green (alternating).
const TProgmemRGBPalette16 TraditionalRedGreen_p FL_PROGMEM =
{  CRGB::Red, CRGB::Green, CRGB::Red, CRGB::Green, 
   CRGB::Red, CRGB::Green, CRGB::Red, CRGB::Green, 
   CRGB::Red, CRGB::Green, CRGB::Red, CRGB::Green, 
   CRGB::Red, CRGB::Green, CRGB::Red, CRGB::Green };

//======================================================================

// A traditional palette with red, green and white (alternating).
// "CRGB::Silver" is used as white to keep the brightness more uniform.
const TProgmemRGBPalette16 TraditionalRedGreenWhite_p FL_PROGMEM =
{  CRGB::Red, CRGB::Red, CRGB::Silver, CRGB::Red, 
   CRGB::Green, CRGB::Silver, CRGB::Green, CRGB::Green, 
   CRGB::Silver, CRGB::Red, CRGB::Green, CRGB::Silver, 
   CRGB::Red, CRGB::Green, CRGB::Silver, CRGB::Green };
   
//======================================================================

const TProgmemRGBPalette16 SolidColorsGreens_p FL_PROGMEM =
{
CRGB::LightGreen,CRGB::LightGreen,CRGB::Green,CRGB::Green,
CRGB::Green,CRGB::Green,CRGB::Green,CRGB::Green,
CRGB::Green,CRGB::LightGreen,CRGB::Green,CRGB::LawnGreen,
CRGB::Green,CRGB::LawnGreen,CRGB::Green,CRGB::Green };

//======================================================================

const TProgmemRGBPalette16 SolidColorsGreens2_p FL_PROGMEM =
{
CRGB::SeaGreen,CRGB::SeaGreen,CRGB::Green,CRGB::Green,
CRGB::SpringGreen,CRGB::SpringGreen,CRGB::SpringGreen,CRGB::SpringGreen,
CRGB::Green,CRGB::SeaGreen,CRGB::Green,CRGB::LawnGreen,
CRGB::Green,CRGB::LawnGreen,CRGB::SpringGreen,CRGB::SpringGreen};

//======================================================================

const TProgmemRGBPalette16 SolidColorsGreens3_p FL_PROGMEM =
{
CRGB::Olive,CRGB::Olive,CRGB::OliveDrab,CRGB::OliveDrab,
CRGB::OliveDrab,CRGB::OliveDrab,CRGB::ForestGreen,CRGB::ForestGreen,
CRGB::ForestGreen,CRGB::ForestGreen,CRGB::Olive,CRGB::Olive,
CRGB::ForestGreen,CRGB::ForestGreen,CRGB::OliveDrab,CRGB::OliveDrab};

//======================================================================

const TProgmemRGBPalette16 Iridescent_p FL_PROGMEM =
{
CRGB::Cyan,CRGB::Cyan,CRGB::Indigo,CRGB::PaleTurquoise,
CRGB::MediumTurquoise,CRGB::Cyan,CRGB::PaleTurquoise,CRGB::CornflowerBlue,
CRGB::Aqua,CRGB::MediumTurquoise,CRGB::Aqua,CRGB::PaleTurquoise,
CRGB::SpringGreen,CRGB::Cyan,CRGB::Indigo,CRGB::MediumTurquoise};

//======================================================================

// Add or remove palette names from this list to control which color
// palettes are used, and in what order.
const TProgmemRGBPalette16* ActivePaletteList[] = {

  &Iridescent_p, 
  &SolidColorsGreens_p,
  &SolidColorsGreens2_p,
  &SolidColorsGreens3_p, 
  &FairyLight_p,
  &PALCandle_p,
  &Ice_p,
  &Ice2_p,  
  &BlueWhite_p,
  &RedWhiteStripes_p,
  &GreenWhiteStripes_p,
  &RedGreenWhite_p,
  &Holly_p,
  &ForestColors_p,  
  &FairyGold_p,
  &TraditionalRedGreenWhite_p,
  &GreenWhite_p,
  &GreenPurple_p,
  &TraditionalRedGreen_p,
  &RedGoldGreen_p,
  &RetroC9_p,
//  &LavaColors_p, //goes too dim
 //  &Snow_p,     //goes too dim
};

// Advance to the next color palette in the list (above).
void chooseNextColorPalette( CRGBPalette16& pal)
{
  const uint8_t numberOfPalettes = sizeof(ActivePaletteList) / sizeof(ActivePaletteList[0]);
  static uint8_t whichPalette = -1; 
  whichPalette = addmod8( whichPalette, 1, numberOfPalettes);

  pal = *(ActivePaletteList[whichPalette]);
}


//*TwinkleFox palette End*


// ColorTwinkles by Mark Kriegsman: https://gist.github.com/kriegsman/5408ecd397744ba0393e

uint8_t solidGreenTwinkles()
{
  gCurrentPalette = SolidColorsGreens_p;
  colortwinkles();
}

uint8_t solidGreen2Twinkles()
{
  gCurrentPalette = SolidColorsGreens2_p;
  colortwinkles();
}

uint8_t solidGreen3Twinkles()
{
  gCurrentPalette = SolidColorsGreens3_p;
  colortwinkles();
}

uint8_t IridescentTwinkles()
{
  gCurrentPalette = Iridescent_p;
  colortwinkles();
}

uint8_t classicTwinkles()
{
  gCurrentPalette = RetroC9_p;
  colortwinkles();
}

uint8_t cloudTwinkles()
{
  gCurrentPalette = CloudColors_p; // Blues and whites!
  colortwinkles();
}

uint8_t rainbowTwinkles()
{
  gCurrentPalette = RainbowColors_p;
  colortwinkles();
}

uint8_t snowTwinkles()
{
  CRGB w(85,85,85), W(CRGB::White);
  gCurrentPalette = CRGBPalette16( W,W,W,W, w,w,w,w, w,w,w,w, w,w,w,w );
  colortwinkles();
}

uint8_t incandescentTwinkles()
{
  CRGB l(0xE1A024);
  gCurrentPalette = CRGBPalette16( l,l,l,l, l,l,l,l, l,l,l,l, l,l,l,l );
  colortwinkles();
}

#define STARTING_BRIGHTNESS GLOBAL_BRIGHTNESS/2
#define FADE_IN_SPEED       20
#define FADE_OUT_SPEED      10
#define DENSITY             3

enum { GETTING_DARKER = 0, GETTING_BRIGHTER = 1 };

void colortwinkles()
{
  // Make each pixel brighter or darker, depending on
  // its 'direction' flag.
  brightenOrDarkenEachPixel( FADE_IN_SPEED, FADE_OUT_SPEED);
  // Now consider adding a new random twinkle
  if( random8() > DENSITY ) {
    int pos = random16(NUM_LEDS);
    if( !leds[pos]) {
      leds[pos] = ColorFromPalette(gCurrentPalette, random8(), STARTING_BRIGHTNESS, LINEARBLEND);
      setPixelDirection(pos, GETTING_BRIGHTER);
    }
  }
}

void brightenOrDarkenEachPixel( fract8 fadeUpAmount, fract8 fadeDownAmount)
{
 for( uint16_t i = 0; i < NUM_LEDS; i++) {
    if( getPixelDirection(i) == GETTING_DARKER) {
      // This pixel is getting darker
      leds[i] = makeDarker( leds[i], fadeDownAmount);
    } else {
      // This pixel is getting brighter
      leds[i] = makeBrighter( leds[i], fadeUpAmount);
      // now check to see if we've maxxed out the brightness
      if( leds[i].r == 255 || leds[i].g == 255 || leds[i].b == 255) {
        // if so, turn around and start getting darker
        setPixelDirection(i, GETTING_DARKER);
      }
    }
  }
}

CRGB makeBrighter( const CRGB& color, fract8 howMuchBrighter)
{
  CRGB incrementalColor = color;
  incrementalColor.nscale8( howMuchBrighter);
  return color + incrementalColor;
}

CRGB makeDarker( const CRGB& color, fract8 howMuchDarker)
{
  CRGB newcolor = color;
  newcolor.nscale8( 255 - howMuchDarker);
  return newcolor;
}

// Compact implementation of
// the directionFlags array, using just one BIT of RAM
// per pixel.  This requires a bunch of bit wrangling,
// but conserves precious RAM.  The cost is a few
// cycles and about 100 bytes of flash program memory.
uint8_t  directionFlags[ (NUM_LEDS+7) / 8];

bool getPixelDirection( uint16_t i)
{
  uint16_t index = i / 8;
  uint8_t  bitNum = i & 0x07;

  uint8_t  andMask = 1 << bitNum;
  return (directionFlags[index] & andMask) != 0;
}

void setPixelDirection( uint16_t i, bool dir)
{
  uint16_t index = i / 8;
  uint8_t  bitNum = i & 0x07;

  uint8_t  orMask = 1 << bitNum;
  uint8_t andMask = 255 - orMask;
  uint8_t value = directionFlags[index] & andMask;
  if( dir ) {
    value += orMask;
  }
  directionFlags[index] = value;
}

//===================================================================================================================================================



//======================================================================
// Normal palettes to use as a pattern.  vvvvv below this point vvvvv
//======================================================================


void palettecloud()
{
// FastLED.setBrightness(GLOBAL_BRIGHTNESS);// Set brightness
  CRGBPalette16 palette = CloudColors_p; LINEARBLEND;
  for( int i = 0; i < NUM_LEDS; i++) { //9948
    leds[i] = ColorFromPalette(palette, gHue+(i*2),GLOBAL_BRIGHTNESS);
  addSparkle(SPARKLEBOMB_AMOUNT);
  }
}

//======================================================================

void paletteocean()
{  
  CRGBPalette16 palette = OceanColors_p;LINEARBLEND;
  
  for( int i = 0; i < NUM_LEDS; i++) { //9948
    leds[i] = ColorFromPalette(palette, gHue+(i*2),GLOBAL_BRIGHTNESS);
  addSparkle(SPARKLEBOMB_AMOUNT);
  }
}

//======================================================================

void paletteforest()
{  
  CRGBPalette16 palette = ForestColors_p;LINEARBLEND;
  
  for( int i = 0; i < NUM_LEDS; i++) { //9948
    leds[i] = ColorFromPalette(palette, gHue+(i*2),GLOBAL_BRIGHTNESS);
  addSparkle(SPARKLEBOMB_AMOUNT);
  }
}

//======================================================================

void palettelava()
{ 
  CRGBPalette16 palette = LavaColors_p;LINEARBLEND;
  
  for( int i = 0; i < NUM_LEDS; i++) { //9948
    leds[i] = ColorFromPalette(palette, gHue+(i),GLOBAL_BRIGHTNESS);
//  addSparkle(SPARKLEBOMB_AMOUNT);
  }
}

//======================================================================

void paletteparty()
{  
  CRGBPalette16 palette = PartyColors_p;LINEARBLEND;
  
  for( int i = 0; i < NUM_LEDS; i++) { //9948
    leds[i] = ColorFromPalette(palette, gHue+(i*2),GLOBAL_BRIGHTNESS);
  addSparkle(SPARKLEBOMB_AMOUNT);
  }
}

//======================================================================

void paletterainbowstripe()
{ 
  CRGBPalette16 palette = RainbowStripeColors_p;NOBLEND;
  
  for( int i = 0; i < NUM_LEDS; i++) { //9948
    leds[i] = ColorFromPalette(palette, gHue+(i*1),GLOBAL_BRIGHTNESS);
  addGlitter(SPARKLEBOMB_AMOUNT);
  }
    FastLED.delay(30);
}

//======================================================================

void paletterainbowstripe2()
{ 
  CRGBPalette16 palette = RainbowStripeColors_p;NOBLEND;
  
  for( int i = 0; i < NUM_LEDS; i++) { //9948
    leds[i] = ColorFromPalette(palette, gHue+(i*2),GLOBAL_BRIGHTNESS);
  addGlitter(SPARKLEBOMB_AMOUNT);
  }
    FastLED.delay(30);
}

//======================================================================

void paletterainbowstripe3()
{ 
  CRGBPalette16 palette = RainbowStripeColors_p;NOBLEND;
  
  for( int i = 0; i < NUM_LEDS; i++) { //9948
    leds[i] = ColorFromPalette(palette, gHue+(i*3),GLOBAL_BRIGHTNESS);
  addGlitter(SPARKLEBOMB_AMOUNT);
  }
    FastLED.delay(30);
}

//======================================================================

void paletteholly()
{  
  CRGBPalette16 palette = Holly_p;LINEARBLEND;
  
  for( int i = 0; i < NUM_LEDS; i++) { //9948
    leds[i] = ColorFromPalette(palette, gHue+(i*2),GLOBAL_BRIGHTNESS);
  }
  addGlitter(GLITTER_AMOUNT/2);  
}

//======================================================================

void paletteFairyLight()
{ 
//  FastLED.setBrightness(GLOBAL_BRIGHTNESS-10);// Set brightness
  CRGBPalette16 palette = FairyLight_p; LINEARBLEND;
  for( int i = 0; i < NUM_LEDS; i++) { //9948
    leds[i] = ColorFromPalette(palette, gHue+(i*2),GLOBAL_BRIGHTNESS);
  }
  addGlitter(GLITTER_AMOUNT); 
} 

//======================================================================

void paletteRetroC9()
{  
  CRGBPalette16 palette = RetroC9_p;NOBLEND;
  
  for( int i = 0; i < NUM_LEDS; i++) { //9948
    leds[i] = ColorFromPalette(palette, gHue+(i*4),GLOBAL_BRIGHTNESS);
}
  addGlitter(GLITTER_AMOUNT);
}

//======================================================================

void paletteFairyGold()
{ 
//  FastLED.setBrightness((GLOBAL_BRIGHTNESS)-10);// Set brightness
  CRGBPalette16 palette = FairyGold_p;LINEARBLEND;
  
  for( int i = 0; i < NUM_LEDS; i++) { //9948
    leds[i] = ColorFromPalette(palette, gHue+(i*1),GLOBAL_BRIGHTNESS);
  addGlitter(GLITTER_AMOUNT/4);
  }
   FastLED.delay(60);
}

//======================================================================
void paletteGreenPurple()
{  
  CRGBPalette16 palette = GreenPurple_p;LINEARBLEND;
  
  for( int i = 0; i < NUM_LEDS; i++) { //9948
    leds[i] = ColorFromPalette(palette, gHue+(i*2),GLOBAL_BRIGHTNESS);
  addSparkle(SPARKLEBOMB_AMOUNT);
  }
}

//======================================================================
void paletteRedGoldGreen()
{ 
  CRGBPalette16 palette = RedGoldGreen_p;LINEARBLEND;
  
  for( int i = 0; i < NUM_LEDS; i++) { //9948
    leds[i] = ColorFromPalette(palette, gHue+(i*2),GLOBAL_BRIGHTNESS);
  addSparkle(SPARKLEBOMB_AMOUNT);
  }
   FastLED.delay(30);
}

//======================================================================
void paletteRedWhiteStripes()
{  
  CRGBPalette16 palette = RedWhiteStripes_p;NOBLEND;
  
  for( int i = 0; i < NUM_LEDS; i++) { //9948
    leds[i] = ColorFromPalette(palette, gHue+(i*2),GLOBAL_BRIGHTNESS);
  addSparkle(SPARKLEBOMB_AMOUNT);
  }
}

//======================================================================
void paletteGreenWhiteStripes()
{  
  CRGBPalette16 palette = GreenWhiteStripes_p;NOBLEND;
  
  for( int i = 0; i < NUM_LEDS; i++) { //9948
    leds[i] = ColorFromPalette(palette, gHue+(i*2),GLOBAL_BRIGHTNESS);
  addSparkle(SPARKLEBOMB_AMOUNT);
  }
}

//======================================================================

void paletteRedGreenWhite()
{  
  CRGBPalette16 palette = RedGreenWhite_p;LINEARBLEND;
  
  for( int i = 0; i < NUM_LEDS; i++) { //9948
    leds[i] = ColorFromPalette(palette, gHue+(i*2),GLOBAL_BRIGHTNESS);
  addSparkle(SPARKLEBOMB_AMOUNT);
  }
}

//======================================================================

void paletteSnow()
{  
  CRGBPalette16 palette = Snow_p;LINEARBLEND;
  
  for( int i = 0; i < NUM_LEDS; i++) { //9948
    leds[i] = ColorFromPalette(palette, gHue+(i*2),GLOBAL_BRIGHTNESS);
//  addSparkle(SPARKLEBOMB_AMOUNT);
  }
 addIridescentSparkle(GLITTER_AMOUNT);
 }

//======================================================================

void paletteBlueWhite()
{  
  CRGBPalette16 palette = BlueWhite_p;LINEARBLEND;
  
  for( int i = 0; i < NUM_LEDS; i++) { //9948
    leds[i] = ColorFromPalette(palette, gHue+(i*2),GLOBAL_BRIGHTNESS);
  }
  addGlitter(GLITTER_AMOUNT);
}

//======================================================================

void paletteGreenWhite()
{  
  CRGBPalette16 palette = GreenWhite_p;LINEARBLEND;
  
  for( int i = 0; i < NUM_LEDS; i++) { //9948
    leds[i] = ColorFromPalette(palette, gHue+(i*2),GLOBAL_BRIGHTNESS);
  }
  addGlitter(GLITTER_AMOUNT);
}

//======================================================================

void paletteIce()
{  
  CRGBPalette16 palette = Ice_p;LINEARBLEND;
  
  for( int i = 0; i < NUM_LEDS; i++) { //9948
    leds[i] = ColorFromPalette(palette, gHue+(i*2),GLOBAL_BRIGHTNESS);
  }
 addIridescentSparkle(GLITTER_AMOUNT);
}

//======================================================================

void paletteIce2()
{  
  CRGBPalette16 palette = Ice2_p;LINEARBLEND;
  
  for( int i = 0; i < NUM_LEDS; i++) { //9948
    leds[i] = ColorFromPalette(palette, gHue+(i*2),GLOBAL_BRIGHTNESS);
 }
 addIridescentSparkle(GLITTER_AMOUNT);
}

//======================================================================

void paletteTraditionalRedGreenWhite()
{  
  CRGBPalette16 palette = TraditionalRedGreenWhite_p;NOBLEND;
  
  for( int i = 0; i < NUM_LEDS; i++) { //9948
    leds[i] = ColorFromPalette(palette,gHue+(i*8),GLOBAL_BRIGHTNESS);
   }
  addGlitter(GLITTER_AMOUNT);
}

//======================================================================

void paletteTraditionalRedGreen()
{  
  CRGBPalette16 palette = TraditionalRedGreen_p;NOBLEND;
  
  for( int i = 0; i < NUM_LEDS; i++) { //9948
    leds[i] = ColorFromPalette(palette, gHue-(i++),GLOBAL_BRIGHTNESS);
  }
}

//======================================================================

void paletteTraditionalRedGreenReverse()
{  
  CRGBPalette16 palette = TraditionalRedGreen_p;NOBLEND;
  
  for( int i = 0; i < NUM_LEDS; i++) { //9948
    leds[i] = ColorFromPalette(palette, gHue+(i++),GLOBAL_BRIGHTNESS);
  }
}

//======================================================================

void paletteRedGreenAlt()
{  
  CRGBPalette16 palette = TraditionalRedGreen_p;NOBLEND;
  
  for( int i = 0; i < NUM_LEDS; i++) { //9948
    leds[i] = ColorFromPalette(palette,gHue=(i*8),GLOBAL_BRIGHTNESS);
  }
  addGlitter(GLITTER_AMOUNT);
}

//======================================================================

void paletteRedGreenAltFlash()
{  
  CRGBPalette16 palette = TraditionalRedGreen_p;NOBLEND;
  
  for( int i = 0; i < NUM_LEDS; i++) { //9948
    leds[i] = ColorFromPalette(palette,gHue+(i*8),GLOBAL_BRIGHTNESS);
//    delay(1);
  }
}

//======================================================================

void paletteBlacklight()
{  
  CRGBPalette16 palette = PALBlacklight_p;
  
  for( int i = 0; i < NUM_LEDS; i++) { //9948
    leds[i] = ColorFromPalette(palette, gHue+(i*2),GLOBAL_BRIGHTNESS);
  addSparkle(SPARKLEBOMB_AMOUNT);
  }
}

//======================================================================

void paletteCandle()
{  
//  FastLED.setBrightness(GLOBAL_BRIGHTNESS-10);// Set brightness
  CRGBPalette16 palette = PALCandle_p;
  
  for( int i = 0; i < NUM_LEDS; i++) { //9948
    leds[i] = ColorFromPalette(palette, gHue+(i*2),GLOBAL_BRIGHTNESS);
  addSparkle(SPARKLEBOMB_AMOUNT);
  }
  addGlitter(GLITTER_AMOUNT);
}

//======================================================================

//  USED BY CANDLE TREE

void addCandles( fract8 chanceOfSparkle)  // like Glitter but flicker instead
{ 
  int i=0;
for(int i; i<NUM_LEDS; i+=5){              // put a "candle" every 5 and now [i] is controlling every 5 only

//   leds[i] += Candleflame;               // solid candle background
  CRGBPalette16 palette = FairyLight_p;LINEARBLEND;   // moving backgrounds
//  CRGBPalette16 palette = PALCandle_p;
//  CRGBPalette16 palette = HeatColors_p;
//  CRGBPalette16 palette = LavaColors_p;
  leds[i] += ColorFromPalette(palette,gHue+(i*8),GLOBAL_BRIGHTNESS);

  if( random8() < chanceOfSparkle) {     // dimming/flicker
    leds[i] += CRGB::Maroon;}            // (Maroon) 

}    
  FastLED.delay(random(0,40));
}

//======================================================================

//  USED BY GREEN RIPPLE

void addGreenRipple( fract8 chanceOfSparkle)  { 
  if( random8() < chanceOfSparkle) {                   //Glitter
    leds[random16(0,NUM_LEDS)] += CRGB::White;}   
  int i=0;
  for(int i; i<NUM_LEDS; i++){              
  CRGBPalette16 palette = RippleGreen_p;LINEARBLEND;   // moving backgrounds
  leds[i] += ColorFromPalette(palette,gHue+(i*8),GLOBAL_BRIGHTNESS);
}
  int j=0;
  for(int j; j<NUM_LEDS; j++){              
  CRGBPalette16 palette = RippleGreen_p;LINEARBLEND;   // moving backgrounds

  leds[j] += ColorFromPalette(palette,gHue-(j*8),GLOBAL_BRIGHTNESS);
}
}

//======================================================================

//  USED BY RED RIPPLE

void addRedRipple( fract8 chanceOfSparkle)  { 
  if( random8() < chanceOfSparkle) {                   //Glitter
    leds[random16(0,NUM_LEDS)] += CRGB::White;}   
  int i=0;
  for(int i; i<NUM_LEDS; i++){              
  CRGBPalette16 palette = RippleRed_p;LINEARBLEND;   // moving backgrounds
  leds[i] += ColorFromPalette(palette,gHue+(i*8),GLOBAL_BRIGHTNESS);
}
  int j=0;
  for(int j; j<NUM_LEDS; j++){              
  CRGBPalette16 palette = RippleRed_p;LINEARBLEND;   // moving backgrounds

  leds[j] += ColorFromPalette(palette,gHue-(j*8),GLOBAL_BRIGHTNESS);
}
}

//======================================================================

//  USED BY BLUE RIPPLE

void addBlueRipple( fract8 chanceOfSparkle)  { 
  if( random8() < chanceOfSparkle) {                   //Glitter
    leds[random16(0,NUM_LEDS)] += CRGB::White;}   
  int i=0;
  for(int i; i<NUM_LEDS; i++){              
  CRGBPalette16 palette = RippleBlue_p;LINEARBLEND;   // moving backgrounds
  leds[i] += ColorFromPalette(palette,gHue+(i*8),GLOBAL_BRIGHTNESS);
}
  int j=0;
  for(int j; j<NUM_LEDS; j++){              
  CRGBPalette16 palette = RippleBlue_p;LINEARBLEND;   // moving backgrounds

  leds[j] += ColorFromPalette(palette,gHue-(j*8),GLOBAL_BRIGHTNESS);
}
}

//======================================================================

//  USED BY YELLOW RIPPLE

void addYellowRipple( fract8 chanceOfSparkle)  { 
  if( random8() < chanceOfSparkle) {                   //Glitter
    leds[random16(0,NUM_LEDS)] += CRGB::White;}   
  int i=0;
  for(int i; i<NUM_LEDS; i++){              
  CRGBPalette16 palette = RippleYellow_p;LINEARBLEND;   // moving backgrounds
  leds[i] += ColorFromPalette(palette,gHue+(i*8),GLOBAL_BRIGHTNESS);
}
  int j=0;
  for(int j; j<NUM_LEDS; j++){              
  CRGBPalette16 palette = RippleYellow_p;LINEARBLEND;   // moving backgrounds

  leds[j] += ColorFromPalette(palette,gHue-(j*8),GLOBAL_BRIGHTNESS);
}
}

//======================================================================

//  USED BY PURPLE RIPPLE

void addPurpleRipple( fract8 chanceOfSparkle)  { 
  if( random8() < chanceOfSparkle) {                   //Glitter
    leds[random16(0,NUM_LEDS)] += CRGB::White;}   
  int i=0;
  for(int i; i<NUM_LEDS; i++){              
  CRGBPalette16 palette = RipplePurple_p;LINEARBLEND;   // moving backgrounds
  leds[i] += ColorFromPalette(palette,gHue+(i*8),GLOBAL_BRIGHTNESS);
}
  int j=0;
  for(int j; j<NUM_LEDS; j++){              
  CRGBPalette16 palette = RipplePurple_p;LINEARBLEND;   // moving backgrounds

  leds[j] += ColorFromPalette(palette,gHue-(j*8),GLOBAL_BRIGHTNESS);
}
}

//======================================================================

//  USED BY TURQUOISE RIPPLE

void addTurquoiseRipple( fract8 chanceOfSparkle)  { 
  if( random8() < chanceOfSparkle) {                   //Glitter
    leds[random16(0,NUM_LEDS)] += CRGB::White;}   
  int i=0;
  for(int i; i<NUM_LEDS; i++){              
  CRGBPalette16 palette = RippleTurquoise_p;LINEARBLEND;   // moving backgrounds
  leds[i] += ColorFromPalette(palette,gHue+(i*8),GLOBAL_BRIGHTNESS);
}
  int j=0;
  for(int j; j<NUM_LEDS; j++){              
  CRGBPalette16 palette = RippleTurquoise_p;LINEARBLEND;   // moving backgrounds

  leds[j] += ColorFromPalette(palette,gHue-(j*8),GLOBAL_BRIGHTNESS);
}
}

//======================================================================

//  USED BY RED WHITE RIPPLE

void addRedWhiteRipple( fract8 chanceOfSparkle)  { 
  if( random8() < chanceOfSparkle) {                   //Glitter
    leds[random16(0,NUM_LEDS)] += CRGB::White;}   
  int i=0;
  for(int i; i<NUM_LEDS; i++){              
  CRGBPalette16 palette = RippleRed_p;LINEARBLEND;   // moving backgrounds
  leds[i] += ColorFromPalette(palette,gHue+(i*8),GLOBAL_BRIGHTNESS);
}
  int j=0;
  for(int j; j<NUM_LEDS; j++){              
  CRGBPalette16 palette = RippleWhite_p;LINEARBLEND;   // moving backgrounds

  leds[j] += ColorFromPalette(palette,gHue-(j*8),GLOBAL_BRIGHTNESS);
}
}

//======================================================================

//  USED BY GREEN WHITE RIPPLE

void addGreenWhiteRipple( fract8 chanceOfSparkle)  { 
  if( random8() < chanceOfSparkle) {                   //Glitter
    leds[random16(0,NUM_LEDS)] += CRGB::White;}   
  int i=0;
  for(int i; i<NUM_LEDS; i++){              
  CRGBPalette16 palette = RippleGreen_p;LINEARBLEND;   // moving backgrounds
  leds[i] += ColorFromPalette(palette,gHue+(i*8),GLOBAL_BRIGHTNESS);
}
  int j=0;
  for(int j; j<NUM_LEDS; j++){              
  CRGBPalette16 palette = RippleWhite_p;LINEARBLEND;   // moving backgrounds

  leds[j] += ColorFromPalette(palette,gHue-(j*8),GLOBAL_BRIGHTNESS);
}
}

//======================================================================

//  USED BY BLUE WHITE RIPPLE

void addBlueWhiteRipple( fract8 chanceOfSparkle)  { 
  if( random8() < chanceOfSparkle) {                   //Glitter
    leds[random16(0,NUM_LEDS)] += CRGB::White;}   
  int i=0;
  for(int i; i<NUM_LEDS; i++){              
  CRGBPalette16 palette = RippleBlue_p;LINEARBLEND;   // moving backgrounds
  leds[i] += ColorFromPalette(palette,gHue+(i*8),GLOBAL_BRIGHTNESS);
}
  int j=0;
  for(int j; j<NUM_LEDS; j++){              
  CRGBPalette16 palette = RippleWhite_p;LINEARBLEND;   // moving backgrounds

  leds[j] += ColorFromPalette(palette,gHue-(j*8),GLOBAL_BRIGHTNESS);
}
}

//======================================================================

//  USED BY PURPLE WHITE RIPPLE

void addPurpleWhiteRipple( fract8 chanceOfSparkle)  { 
  if( random8() < chanceOfSparkle) {                   //Glitter
    leds[random16(0,NUM_LEDS)] += CRGB::White;}   
  int i=0;
  for(int i; i<NUM_LEDS; i++){              
  CRGBPalette16 palette = RipplePurple_p;LINEARBLEND;   // moving backgrounds
  leds[i] += ColorFromPalette(palette,gHue+(i*8),GLOBAL_BRIGHTNESS);
}
  int j=0;
  for(int j; j<NUM_LEDS; j++){              
  CRGBPalette16 palette = RippleWhite_p;LINEARBLEND;   // moving backgrounds

  leds[j] += ColorFromPalette(palette,gHue-(j*8),GLOBAL_BRIGHTNESS);
}
}

//======================================================================

//  USED BY YELLOW WHITE RIPPLE

void addYellowWhiteRipple( fract8 chanceOfSparkle)  { 
  if( random8() < chanceOfSparkle) {                   //Glitter
    leds[random16(0,NUM_LEDS)] += CRGB::White;}   
  int i=0;
  for(int i; i<NUM_LEDS; i++){              
  CRGBPalette16 palette = RippleYellow_p;LINEARBLEND;   // moving backgrounds
  leds[i] += ColorFromPalette(palette,gHue+(i*8),GLOBAL_BRIGHTNESS);
}
  int j=0;
  for(int j; j<NUM_LEDS; j++){              
  CRGBPalette16 palette = RippleWhite_p;LINEARBLEND;   // moving backgrounds

  leds[j] += ColorFromPalette(palette,gHue-(j*8),GLOBAL_BRIGHTNESS);
}
}

//======================================================================

//  USED BY TURQUOISE WHITE RIPPLE

void addTurquoiseWhiteRipple( fract8 chanceOfSparkle)  { 
  if( random8() < chanceOfSparkle) {                   //Glitter
    leds[random16(0,NUM_LEDS)] += CRGB::White;}   
  int i=0;
  for(int i; i<NUM_LEDS; i++){              
  CRGBPalette16 palette = RippleTurquoise_p;LINEARBLEND;   // moving backgrounds
  leds[i] += ColorFromPalette(palette,gHue+(i*8),GLOBAL_BRIGHTNESS);
}
  int j=0;
  for(int j; j<NUM_LEDS; j++){              
  CRGBPalette16 palette = RippleWhite_p;LINEARBLEND;   // moving backgrounds

  leds[j] += ColorFromPalette(palette,gHue-(j*8),GLOBAL_BRIGHTNESS);
}
}

//======================================================================

//  USED BY GREEN BLUE RIPPLE

void addGreenBlueRipple( fract8 chanceOfSparkle)  { 
  if( random8() < chanceOfSparkle) {                   //Glitter
    leds[random16(0,NUM_LEDS)] += CRGB::White;}   
  int i=0;
  for(int i; i<NUM_LEDS; i++){              
  CRGBPalette16 palette = RippleGreen_p;LINEARBLEND;   // moving backgrounds
  leds[i] += ColorFromPalette(palette,gHue+(i*8),GLOBAL_BRIGHTNESS);
}
  int j=0;
  for(int j; j<NUM_LEDS; j++){              
  CRGBPalette16 palette = RippleBlue_p;LINEARBLEND;   // moving backgrounds

  leds[j] += ColorFromPalette(palette,gHue-(j*8),GLOBAL_BRIGHTNESS);
}
}

//======================================================================

//  USED BY TURQUOISE PURPLE RIPPLE

void addTurquoisePurpleRipple( fract8 chanceOfSparkle)  { 
  if( random8() < chanceOfSparkle) {                   //Glitter
    leds[random16(0,NUM_LEDS)] += CRGB::White;}   
  int i=0;
  for(int i; i<NUM_LEDS; i++){              
  CRGBPalette16 palette = RippleTurquoise_p;LINEARBLEND;   // moving backgrounds
  leds[i] += ColorFromPalette(palette,gHue+(i*8),GLOBAL_BRIGHTNESS);
}
  int j=0;
  for(int j; j<NUM_LEDS; j++){              
  CRGBPalette16 palette = RipplePurple_p;LINEARBLEND;   // moving backgrounds

  leds[j] += ColorFromPalette(palette,gHue-(j*8),GLOBAL_BRIGHTNESS);
}
}

//======================================================================

//  USED BY YELLOW RED RIPPLE

void addYellowRedRipple( fract8 chanceOfSparkle)  { 
  if( random8() < chanceOfSparkle) {                   //Glitter
    leds[random16(0,NUM_LEDS)] += CRGB::White;}   
  int i=0;
  for(int i; i<NUM_LEDS; i++){              
  CRGBPalette16 palette = RippleYellow_p;LINEARBLEND;   // moving backgrounds
  leds[i] += ColorFromPalette(palette,gHue+(i*8),GLOBAL_BRIGHTNESS);
}
  int j=0;
  for(int j; j<NUM_LEDS; j++){              
  CRGBPalette16 palette = RippleRed_p;LINEARBLEND;   // moving backgrounds

  leds[j] += ColorFromPalette(palette,gHue-(j*8),GLOBAL_BRIGHTNESS);
}
}

//======================================================================

void BlacklightON()  // messes up color temps on exit :( shame...
{
   FastLED.setTemperature(BlackLightFluorescent); // culprit... You need to reset color temp back to normal on exit  
   fill_solid(leds,NUM_LEDS,(BlackLightFluorescent));//fill strip
}

//======================================================================    

void CandleON()  // messes up color temps on exit :(
{
   FastLED.setTemperature(Candle);  // culprit... You need to reset color temp back to normal on exit
   fill_solid(leds,NUM_LEDS,(Candle));//fill strip
   FastLED.delay(50);
    addSparkle(GLITTER_AMOUNT);
    addGlitter(GLITTER_AMOUNT);
}

//======================================================================    

void clear_leds()
{
  fadeToBlackBy( leds, NUM_LEDS,120);
  FastLED.clear();
}


//======================================================================    
//*Palette list End*  


//                                      ----------------                                                 //
   ///////////////////////////////////     TWINKLEFOX      ////////////////////////////////////////////
//                                      ----------------                                                 //

//=========================================================================================================

// The following code is from Mark Kriegsman.  ( Twinkle-Lights 2015 )
// G+:    https://plus.google.com/u/0/112916219338292742137/posts/XWiEEeDxFWZ?sfc=true
// CODE:  https://gist.github.com/kriegsman/756ea6dcae8e30845b5a

// THANKYOU MARK!! X


//  TwinkleFOX: Twinkling 'holiday' lights that fade in and out.
//  Colors are chosen from a palette; a few palettes are provided.-( See Palettes tab )

// Overall twinkle speed.
// 0 (VERY slow) to 8 (VERY fast).  
// 4, 5, and 6 are recommended, default is 4.
#define TWINKLE_SPEED 4  

// Overall twinkle density.
// 0 (NONE lit) to 8 (ALL lit at once).  
// Default is 5.
#define TWINKLE_DENSITY 8

// Background color for 'unlit' pixels
// Can be set to CRGB::Black if desired.
CRGB gBackgroundColor = CRGB::Black; 
// Example of dim incandescent fairy light background color
//CRGB gBackgroundColor = CRGB(CRGB::FairyLight).nscale8_video(16);

// If AUTO_SELECT_BACKGROUND_COLOR is set to 1,
// then for any palette where the first two entries 
// are the same, a dimmed version of that color will
// automatically be used as the background color.
#define AUTO_SELECT_BACKGROUND_COLOR 1

// If COOL_LIKE_INCANDESCENT is set to 1, colors will 
// fade out slighted 'reddened', similar to how
// incandescent bulbs change color as they get dim down.
#define COOL_LIKE_INCANDESCENT 1

//=========================================================================================================

void TwinkleFox()
{
  // "PRNG16" is the pseudorandom number generator
  // It MUST be reset to the same starting value each time
  // this function is called, so that the sequence of 'random'
  // numbers that it generates is (paradoxically) stable.
  uint16_t PRNG16 = 11337;
  
  uint32_t clock32 = millis();

  // Set up the background color, "bg".
  // if AUTO_SELECT_BACKGROUND_COLOR == 1, and the first two colors of
  // the current palette are identical, then a deeply faded version of
  // that color is used for the background color
  CRGB bg;
  if( (AUTO_SELECT_BACKGROUND_COLOR == 1) &&
      (gCurrentPalette[0] == gCurrentPalette[1] )) {
    bg = gCurrentPalette[0];
    uint8_t bglight = bg.getAverageLight();
    if( bglight > 64) {
      bg.nscale8_video( 16); // very bright, so scale to 1/16th
    } else if( bglight > 16) {
      bg.nscale8_video( 64); // not that bright, so scale to 1/4th
    } else {
      bg.nscale8_video( 86); // dim, scale to 1/3rd.
    }
  } else {
    bg = gBackgroundColor; // just use the explicitly defined background color
  }

  uint8_t backgroundBrightness = bg.getAverageLight();
  
  for( CRGB& pixel: leds) {
    PRNG16 = (uint16_t)(PRNG16 * 2053) + 1384; // next 'random' number
    uint16_t myclockoffset16= PRNG16; // use that number as clock offset
    PRNG16 = (uint16_t)(PRNG16 * 2053) + 1384; // next 'random' number
    // use that number as clock speed adjustment factor (in 8ths, from 8/8ths to 23/8ths)
    uint8_t myspeedmultiplierQ5_3 =  ((((PRNG16 & 0xFF)>>4) + (PRNG16 & 0x0F)) & 0x0F) + 0x08;
    uint32_t myclock30 = (uint32_t)((clock32 * myspeedmultiplierQ5_3) >> 3) + myclockoffset16;
    uint8_t  myunique8 = PRNG16 >> 8; // get 'salt' value for this pixel

    // We now have the adjusted 'clock' for this pixel, now we call
    // the function that computes what color the pixel should be based
    // on the "brightness = f( time )" idea.
    CRGB c = computeOneTwinkle( myclock30, myunique8);

    uint8_t cbright = c.getAverageLight();
    int16_t deltabright = cbright - backgroundBrightness;
    if( deltabright >= 32 || (!bg)) {
      // If the new pixel is significantly brighter than the background color, 
      // use the new color.
      pixel = c;
    } else if( deltabright > 0 ) {
      // If the new pixel is just slightly brighter than the background color,
      // mix a blend of the new color and the background color
      pixel = blend( bg, c, deltabright * 8);
    } else { 
      // if the new pixel is not at all brighter than the background color,
      // just use the background color.
      pixel = bg;
    }
  }
//      addGlitter(1);  // Can be a bit much - Try it and see!
}

//=========================================================================================================


//  This function takes a time in pseudo-milliseconds,
//  figures out brightness = f( time ), and also hue = f( time )
//  The 'low digits' of the millisecond time are used as 
//  input to the brightness wave function.  
//  The 'high digits' are used to select a color, so that the color
//  does not change over the course of the fade-in, fade-out
//  of one cycle of the brightness wave function.
//  The 'high digits' are also used to determine whether this pixel
//  should light at all during this cycle, based on the TWINKLE_DENSITY.
CRGB computeOneTwinkle( uint32_t ms, uint8_t salt)
{
  uint16_t ticks = ms >> (8-TWINKLE_SPEED);
  uint8_t fastcycle8 = ticks;
  uint16_t slowcycle16 = (ticks >> 8) + salt;
  slowcycle16 += sin8( slowcycle16);
  slowcycle16 =  (slowcycle16 * 2053) + 1384;
  uint8_t slowcycle8 = (slowcycle16 & 0xFF) + (slowcycle16 >> 8);
  
  uint8_t bright = 0;
  if( ((slowcycle8 & 0x0E)/2) < TWINKLE_DENSITY) {
    bright = attackDecayWave8( fastcycle8);
  }

  uint8_t hue = slowcycle8 - salt;
  CRGB c;
  if( bright > 0) {
    c = ColorFromPalette( gCurrentPalette, hue, bright, NOBLEND);
    if( COOL_LIKE_INCANDESCENT == 1 ) {
      coolLikeIncandescent( c, fastcycle8);
    }
  } else {
    c = CRGB::Black;
  }
  return c;

}

//=========================================================================================================

// This function is like 'triwave8', which produces a 
// symmetrical up-and-down triangle sawtooth waveform, except that this
// function produces a triangle wave with a faster attack and a slower decay:
//
//     / \ 
//    /     \ 
//   /         \ 
//  /             \ 
//

uint8_t attackDecayWave8( uint8_t i)
{
  if( i < 86) {
    return i * 3;
  } else {
    i -= 86;
    return 255 - (i + (i/2));
  }
}

//=========================================================================================================

// This function takes a pixel, and if its in the 'fading down'
// part of the cycle, it adjusts the color a little bit like the 
// way that incandescent bulbs fade toward 'red' as they dim.
void coolLikeIncandescent( CRGB& c, uint8_t phase)
{
  if( phase < 128) return;

  uint8_t cooling = (phase - 128) >> 4;
  c.g = qsub8( c.g, cooling);
  c.b = qsub8( c.b, cooling * 2);
}

//=========================================================================================================
/*
        ____
     .-" +' "-.    __,  ,___,
    /.'.'A_'*`.\  (--|__| _,,_ ,_
   |:.*'/\-\. ':|   _|  |(_||_)|_)\/
   |:.'.||"|.'*:|  (        |  | _/
    \:~^~^~^~^:/          __,  ,___,
     /`-....-'\          (--|__| _ |' _| _,   ,
    /          \           _|  |(_)||(_|(_|\//_)
    `-.,____,.-'          (               _/

*/
//=========================================================================================================



//                                      ----------------                                                 //
   //////////////////////////////////     ALL PATTERNS    ////////////////////////////////////////////
//                                      ----------------                                                 //
//Here are ALL the Animations and patterns - Sorry if your pattern has no shout-out... I lost track!
//(I TOLD THE ELVES NOT TO DECORATE HERE) - (FOR EASY COPYING TO YOUR OWN SKETCHES)

//======================================================================

void addGlitter( fract8 chanceOfGlitter) 
{
  if( random8() < chanceOfGlitter) {
    leds[ random16(NUM_LEDS) ] += CRGB::White;
  }
}

//======================================================================

void addSparkle( fract8 chanceOfSparkle) 
{
  if( random8() < chanceOfSparkle) {
    leds[ random16(NUM_LEDS) ] += CRGB::Gold;
    leds[ random16(NUM_LEDS) ] += CRGB::White;     
  }
}

//======================================================================

void addIridescentSparkle( fract8 chanceOfSparkle) 
{
  if( random8() < chanceOfSparkle) {
    leds[random16(NUM_LEDS)] += CRGB::Purple;
    leds[random16(NUM_LEDS)] += CRGB::Cyan;
  }
}

//======================================================================

void addSparklebomb( fract8 chanceOfSparkle) 
{
  if( random8() < chanceOfSparkle) {
    leds[ random16(NUM_LEDS) ] += CRGB::White;
    leds[ random16(NUM_LEDS) ] += CRGB::FairyLight;
    leds[ random16(NUM_LEDS) ] += CRGB::Silver;
    leds[ random16(NUM_LEDS) ] += CRGB::FairyLightNCC;
   }
}

//======================================================================

void addOldSchoolSparkle1( fract8 chanceOfSparkle) 
{
  if( random8() < chanceOfSparkle) {
    leds[ random16(NUM_LEDS) ] += CRGB::FairyLight;
    leds[ random16(NUM_LEDS) ] += CRGB::FairyLightNCC;    
    leds[ random16(NUM_LEDS) ] += CRGB::White;
  }
}

//======================================================================

void addOldSchoolSparkle2( fract8 chanceOfSparkle) 
{
  if( random8() < chanceOfSparkle) {
    leds[ random16(NUM_LEDS) ] += CRGB::FairyLightNCC;     
    leds[ random16(NUM_LEDS) ] += CRGB::Yellow;
    leds[ random16(NUM_LEDS) ] += CRGB::Gold;
  }
}

//======================================================================

void addGreenSparkle( fract8 chanceOfSparkle) 
{
  if( random8() < chanceOfSparkle) {
    leds[ random16(NUM_LEDS) ] += CRGB::Green;
    leds[ random8(NUM_LEDS) ] += CRGB::White;
  }
}
//======================================================================

void addRedSparkle( fract8 chanceOfSparkle) 
{
  if( random8() < chanceOfSparkle) {
    leds[ random16(NUM_LEDS) ] += CRGB::Red;     
    leds[ random8(NUM_LEDS) ] += CRGB::White;
  }
}
//======================================================================

void addBlueSparkle( fract8 chanceOfSparkle) 
{
  if( random8() < chanceOfSparkle) {
    leds[ random16(NUM_LEDS) ] += CRGB::Blue;
    leds[ random8(NUM_LEDS) ] += CRGB::White;
  }
}
//======================================================================

void addGlimmer( fract8 chanceOfGlitter) 
{
  int pos = beatsin16(15,1,NUM_LEDS-1);  // (speed , start , end)
  leds[pos] = CRGB( 130, GLOBAL_BRIGHTNESS, GLOBAL_BRIGHTNESS);     // (hue, sat , brightness)

  if( random8() < chanceOfGlitter) {
  leds[random16(0,pos)] += CRGB( 255, 0, GLOBAL_BRIGHTNESS);        
  leds[random16(pos,NUM_LEDS)] += CRGB( 255, 0, GLOBAL_BRIGHTNESS); 
  }
}

//======================================================================

void rainbow_pulse() 
{
    thishue++;
    if (thishue > 255) {thishue = 0;}
    for(int idex = 0 ; idex < NUM_LEDS; idex++ ) {
      leds[idex] = CHSV(thishue, thissat, GLOBAL_BRIGHTNESS);    
    }
      addGlitter(GLITTER_AMOUNT);
}

//======================================================================

void rainbow_pulse2() 
{
    thishue++;
    if (thishue > 255) {thishue = 0;}
    for(int idex = 0 ; idex < NUM_LEDS; idex++ ) {
      leds[idex] = CHSV(thishue, thissat, GLOBAL_BRIGHTNESS);    
      leds[random8(0,NUM_LEDS)] = CHSV(thishue+25, thissat, GLOBAL_BRIGHTNESS);    
    }
FastLED.delay(60);
     addGlitter(GLITTER_AMOUNT);
}

//======================================================================

void bighalfrainbow() 
{
  // FastLED's built-in rainbow generator
  fill_rainbow( leds, NUM_LEDS, gHue, 1);
  addGlitter(GLITTER_AMOUNT);
}

//======================================================================

void bigrainbow() 
{
  // FastLED's built-in rainbow generator
  fill_rainbow( leds, NUM_LEDS, gHue, 2);
  addGlitter(GLITTER_AMOUNT);
  
}

//======================================================================

void rainbow() 
{
  // FastLED's built-in rainbow generator
  fill_rainbow( leds, NUM_LEDS, gHue, 15);
  addGlitter(GLITTER_AMOUNT);
}

//======================================================================

void miniRainbow() 
{
  // FastLED's built-in rainbow generator
  fill_rainbow( leds, NUM_LEDS, gHue, 31);
  addGlitter(GLITTER_AMOUNT);
}

//======================================================================

void rainbowDots() 
{
  // FastLED's built-in rainbow generator
  fill_rainbow( leds, NUM_LEDS, gHue, 62);
  addGlitter(GLITTER_AMOUNT);
}

//======================================================================

void confetti() 
{
  {// random colored speckles that blink in and fade smoothly
  fadeToBlackBy( leds, NUM_LEDS, FADEOUT_SPEED/4);
  int pos = random16(NUM_LEDS);
  leds[pos] += CHSV( gHue + random8(64), 200, 255);
  }
  addGlitter(GLITTER_AMOUNT/4);
}

//======================================================================

void justGlitter() 
{
  // built-in FastLED rainbow, plus some random sparkly glitter
  fadeToBlackBy( leds, NUM_LEDS, FADEOUT_SPEED);
  addGlitter(GLITTER_AMOUNT);
}

//======================================================================

void justSparkle() 
{
  // built-in FastLED rainbow, plus some random sparkly glitter
  fadeToBlackBy( leds, NUM_LEDS, FADEOUT_SPEED);
  addSparkle(SPARKLE_AMOUNT);
}

//======================================================================

void justSparkleOldSchool1() 
{
  // built-in FastLED rainbow, plus some random sparkly glitter
  fadeToBlackBy( leds, NUM_LEDS, FADEOUT_SPEED);
  addOldSchoolSparkle1(GLITTER_AMOUNT);
}

//======================================================================

void justSparkleOldSchool2() 
{
  // built-in FastLED rainbow, plus some random sparkly glitter
  fadeToBlackBy( leds, NUM_LEDS, FADEOUT_SPEED);
  addOldSchoolSparkle2(GLITTER_AMOUNT);
}

//======================================================================

void IridescentSparkle() 
{ 
  fill_solid(leds,NUM_LEDS,CHSV (ghue,70,(GLOBAL_BRIGHTNESS)));
  addIridescentSparkle(GLITTER_AMOUNT/2);
}
//======================================================================

void CandleTree1() 
{ 
  fadeToBlackBy( leds, NUM_LEDS, FADEOUT_SPEED);
  fill_solid(leds,NUM_LEDS,CHSV (0,255,(GLOBAL_BRIGHTNESS)));
  addCandles(2);        //chance of flicker
}
//======================================================================
  
void CandleTree2() 
{ 
  fadeToBlackBy( leds, NUM_LEDS, FADEOUT_SPEED);
  fill_solid(leds,NUM_LEDS,CHSV (85,255,(GLOBAL_BRIGHTNESS)));
  addCandles(2);        //chance of flicker
}
//======================================================================
  
void CandleTree3() 
{ 
  fadeToBlackBy( leds, NUM_LEDS, FADEOUT_SPEED);
  fill_solid(leds,NUM_LEDS,CHSV (150,255,(GLOBAL_BRIGHTNESS)));
  addCandles(2);        //chance of flicker
}
//======================================================================
  
void CandleTree4() 
{ 
  fadeToBlackBy( leds, NUM_LEDS, FADEOUT_SPEED);
  fill_solid(leds,NUM_LEDS,CHSV (42,255,(GLOBAL_BRIGHTNESS)));
  addCandles(2);        //chance of flicker
}
//======================================================================

void GreenSparkle() 
{
  // built-in FastLED rainbow, plus some random sparkly glitter
  fadeToBlackBy( leds, NUM_LEDS, FADEOUT_SPEED/2);
  addGreenSparkle(GLITTER_AMOUNT*2);
}

//======================================================================

void RedSparkle() 
{
  // built-in FastLED rainbow, plus some random sparkly glitter
  fadeToBlackBy( leds, NUM_LEDS, FADEOUT_SPEED/2);
  addRedSparkle(GLITTER_AMOUNT*2);
}

//======================================================================

void BlueSparkle() 
{
  // built-in FastLED rainbow, plus some random sparkly glitter
  fadeToBlackBy( leds, NUM_LEDS, FADEOUT_SPEED/2);
  addBlueSparkle(GLITTER_AMOUNT*2);
}

//======================================================================

void rgbSparkle() 
{
  // built-in FastLED rainbow, plus some random sparkly glitter
  fadeToBlackBy( leds, NUM_LEDS, FADEOUT_SPEED/2);
  addGreenSparkle(GLITTER_AMOUNT);
  addRedSparkle(GLITTER_AMOUNT);
  addBlueSparkle(GLITTER_AMOUNT);
}

//======================================================================

void Glimmer() 
{ 
  fill_solid(leds,NUM_LEDS,CHSV (90,255,GLOBAL_BRIGHTNESS));
  addGlimmer(GLITTER_AMOUNT);
//FastLED.delay(30);
}

//======================================================================

void RedRipple() 
{
  fadeToBlackBy( leds, NUM_LEDS, FADEOUT_SPEED);
  addRedRipple(GLITTER_AMOUNT/4);
//FastLED.delay(30);
}

//======================================================================

void GreenRipple() 
{
  fadeToBlackBy( leds, NUM_LEDS, FADEOUT_SPEED);
  addGreenRipple(GLITTER_AMOUNT/4);
//FastLED.delay(30);
}

//======================================================================

void BlueRipple() 
{
  fadeToBlackBy( leds, NUM_LEDS, FADEOUT_SPEED);
  addBlueRipple(GLITTER_AMOUNT/4);
//FastLED.delay(30);
}

//======================================================================

void PurpleRipple() 
{
  fadeToBlackBy( leds, NUM_LEDS, FADEOUT_SPEED);
  addPurpleRipple(GLITTER_AMOUNT/4);
//FastLED.delay(30);
}

//======================================================================

void TurquoiseRipple() 
{
  fadeToBlackBy( leds, NUM_LEDS, FADEOUT_SPEED);
  addTurquoiseRipple(GLITTER_AMOUNT/4);
//FastLED.delay(30);
}

//======================================================================

void YellowRipple() 
{
  fadeToBlackBy( leds, NUM_LEDS, FADEOUT_SPEED);
  addYellowRipple(GLITTER_AMOUNT/4);
//FastLED.delay(30);
}

//======================================================================

void RedWhiteRipple() 
{
  fadeToBlackBy( leds, NUM_LEDS, FADEOUT_SPEED);
  addRedWhiteRipple(GLITTER_AMOUNT/4);
//FastLED.delay(30);
}

//======================================================================

void GreenWhiteRipple() 
{
  fadeToBlackBy( leds, NUM_LEDS, FADEOUT_SPEED);
  addGreenWhiteRipple(GLITTER_AMOUNT/4);
//FastLED.delay(30);
}

//======================================================================

void BlueWhiteRipple() 
{
  fadeToBlackBy( leds, NUM_LEDS, FADEOUT_SPEED);
  addBlueWhiteRipple(GLITTER_AMOUNT/4);
//FastLED.delay(30);
}

//======================================================================

void PurpleWhiteRipple() 
{
  fadeToBlackBy( leds, NUM_LEDS, FADEOUT_SPEED);
  addPurpleWhiteRipple(GLITTER_AMOUNT/4);
//FastLED.delay(30);
}

//======================================================================

void TurquoiseWhiteRipple() 
{
  fadeToBlackBy( leds, NUM_LEDS, FADEOUT_SPEED);
  addTurquoiseWhiteRipple(GLITTER_AMOUNT/4);
//FastLED.delay(30);
}

//======================================================================

void YellowWhiteRipple() 
{
  fadeToBlackBy( leds, NUM_LEDS, FADEOUT_SPEED);
  addYellowWhiteRipple(GLITTER_AMOUNT/4);
//FastLED.delay(30);
}

//======================================================================

void GreenBlueRipple() 
{
  fadeToBlackBy( leds, NUM_LEDS, FADEOUT_SPEED);
  addGreenBlueRipple(GLITTER_AMOUNT/4),GLOBAL_BRIGHTNESS;
//FastLED.delay(30);
}

//======================================================================

void YellowRedRipple() 
{
  fadeToBlackBy( leds, NUM_LEDS, FADEOUT_SPEED);
  addYellowRedRipple(GLITTER_AMOUNT/4);
//FastLED.delay(30);
}

//======================================================================

void TurquoisePurpleRipple() 
{
  fadeToBlackBy( leds, NUM_LEDS, FADEOUT_SPEED);
  addTurquoisePurpleRipple(GLITTER_AMOUNT/4);
//FastLED.delay(30);
}

//======================================================================

void juggle() {
  // eight colored dots, weaving in and out of sync with each other
  fadeToBlackBy( leds, NUM_LEDS, FADEOUT_SPEED/2);

  byte dothue = 0;
  for( int i = 0; i < 8; i++) {
    leds[beatsin16(i+2,0,NUM_LEDS)] |= CHSV(dothue, 250, GLOBAL_BRIGHTNESS);
    dothue += 32;

    }
//    addGlitter(GLITTER_AMOUNT);
}

//======================================================================

void sinelon()    // Original full color
{
  // a colored dot sweeping back and forth, with fading trails
  fadeToBlackBy( leds, NUM_LEDS, FADEOUT_SPEED/32);

  int pos = beatsin16(5,1,NUM_LEDS-1);
  leds[pos] += CHSV( gHue, 255, GLOBAL_BRIGHTNESS);

//  addGlitter(GLITTER_AMOUNT);
}

//======================================================================

void sinelon2()    // Original half color (pastel)
{
  // a pastel colored dot sweeping back and forth, with fading trails
  fadeToBlackBy( leds, NUM_LEDS, FADEOUT_SPEED/32);

  int pos = beatsin16(5,1,NUM_LEDS-1);
  leds[pos] += CHSV( gHue, 170, GLOBAL_BRIGHTNESS);

//  addGlitter(GLITTER_AMOUNT);
}

//======================================================================

void sinelonWhite()  // Original no color
{
  // a white dot sweeping back and forth, with fading trails
  fadeToBlackBy( leds, NUM_LEDS, FADEOUT_SPEED/32);

  int pos = beatsin16(10,1,NUM_LEDS-1);
  leds[pos] += CHSV( gHue, 1, GLOBAL_BRIGHTNESS);

//  addOldSchoolSparkle2(SPARKLE_AMOUNT);
}

//======================================================================

void random_burst() 
{
  int rndidx = random16(0, NUM_LEDS);
  int rndhue = random8(50, 200);  
  int rndbright = random8((GLOBAL_BRIGHTNESS-5), GLOBAL_BRIGHTNESS);
  leds[rndidx] = CHSV(rndhue, thissat, GLOBAL_BRIGHTNESS);
}

//======================================================================

void rgb_propeller() 
{
  thishue = 0;
  index++;
  int ghue = (thishue + 85) % 255;
  int bhue = (thishue + 171) % 255;
  int N3  = int(NUM_LEDS/3);
  int N6  = int(NUM_LEDS/6);  
  int N12 = int(NUM_LEDS/12);  
  for(int i = 0; i < N3; i++ ) {
    int j0 = (index + i + NUM_LEDS - N12) % NUM_LEDS;
    int j1 = (j0+N3) % NUM_LEDS;
    int j2 = (j1+N3) % NUM_LEDS;    
    leds[j0].maximizeBrightness();leds[j0] = CHSV(thishue, thissat, GLOBAL_BRIGHTNESS);
    leds[j1].maximizeBrightness();leds[j1]  = CHSV(ghue, thissat, GLOBAL_BRIGHTNESS);
    leds[j2].maximizeBrightness();leds[j2]  = CHSV(bhue, thissat, GLOBAL_BRIGHTNESS);    
  }
      FastLED.delay(30);
//  addGlitter(GLITTER_AMOUNT);
}

//======================================================================

void fill_rainbow_3(struct CRGB * pFirstLED, int numToFill, uint8_t initialhue, uint8_t deltahue, uint8_t saturation, uint8_t brightness)
{
    CHSV hsv;
    hsv.hue = initialhue;
    hsv.sat = saturation;
    hsv.val = GLOBAL_BRIGHTNESS;

    for( int i = 0; i < numToFill; i++) {
        hsv2rgb_rainbow( hsv, pFirstLED[i]);
        hsv.hue += deltahue;
    }
}
void rainbow3()
{
  fill_rainbow_3( leds, NUM_LEDS, thishue, thisstep, thissat, GLOBAL_BRIGHTNESS);
  thishue++;
  addSparkle(GLITTER_AMOUNT);
}

//======================================================================

void rainbow_loop() 
{
  
  index++;
  thishue = thishue + thisstep;
  if (index >= NUM_LEDS) {index = 0;}
  if (thishue > 255) {thishue = 0;}
  leds[index] = CHSV(thishue, thissat, GLOBAL_BRIGHTNESS);

//  addGlitter(10);
}

//======================================================================

void matrix1()  // Green base with Red dots.
{
  
  int rand = random8(230, 255);
  if (rand > 250) {
    leds[0] = CHSV(255, thissat, GLOBAL_BRIGHTNESS);   // 0=Red ,50=Yellowish, 100=Green , 150=Blue, 200=Purple, 255=Red
  }
  else {
    leds[0] = CHSV(100, thissat, GLOBAL_BRIGHTNESS);
  }

  for(int i = NUM_LEDS-1; i > 0; i--) 
  {
    leds[i] = leds[i-1];
  } 
    FastLED.delay(60);
}

//======================================================================

void matrix2()  // Blue base with Green dots.
{
  
  int rand = random8(230, 255);
  if (rand > 250) {
    leds[0] = CHSV(100, thissat, GLOBAL_BRIGHTNESS);   // 0=Red ,50=Yellowish, 100=Green , 150=Blue, 200=Purple, 255=Red

  }
  else {
    leds[0] = CHSV(150, thissat, GLOBAL_BRIGHTNESS);
  }

  for(int i = NUM_LEDS-1; i > 0; i--) 
  {
    leds[i] = leds[i-1];
  } 
    FastLED.delay(60);
}

//======================================================================

void matrix3()  // Red base with Green dots.
{
  int rand = random8(230, 255);
  if (rand > 250) {
    leds[0] = CHSV(100, thissat, GLOBAL_BRIGHTNESS);   // 0=Red ,50=Yellowish, 100=Green , 150=Blue, 200=Purple, 255=Red
  }
  else {
    leds[0] = CHSV(255, thissat, GLOBAL_BRIGHTNESS);
  }

  for(int i = NUM_LEDS-1; i > 0; i--) 
  {
    leds[i] = leds[i-1];
  } 
    FastLED.delay(60);
}

//======================================================================

void matrix4()  // Light Green base with (dull)Yellow dots.
{
  int rand = random8(230, 255);
  if (rand > 250) {
    leds[NUM_LEDS] = CHSV(60, thissat, GLOBAL_BRIGHTNESS);   // 0=Red ,50=Yellowish, 100=Green , 150=Blue, 200=Purple, 255=Red
  }
  else {
    leds[NUM_LEDS] = CHSV(120, thissat, GLOBAL_BRIGHTNESS);
  }

  for(int i = 0; i < NUM_LEDS; i++) 
  {
    leds[i] = leds[i+1]; 
  } 
    FastLED.delay(60);
}

//======================================================================

void matrix5()  // Light Green base with Red dots.
{
  int rand = random8(230, 255);
  if (rand > 250) {
    leds[NUM_LEDS] = CHSV(255, thissat, GLOBAL_BRIGHTNESS);   // 0=Red ,50=Yellowish, 100=Green , 150=Blue, 200=Purple, 255=Red
                                                
}
  else {
    leds[NUM_LEDS] = CHSV(120, thissat, GLOBAL_BRIGHTNESS);
  }

  for(int i = 0; i < NUM_LEDS; i++) 
  {
    leds[i] = leds[i+1]; 
  } 
    FastLED.delay(60);
 }

//======================================================================

void matrix6()  // Light White base with Purple dots.
{
  int rand = random8(230, 255);
  if (rand > 250) {
    leds[NUM_LEDS] = CHSV(200, 255, GLOBAL_BRIGHTNESS);   // 0=Red ,50=Yellowish, 100=Green , 150=Blue, 200=Purple, 255=Red
                                               
}
  else {
    leds[NUM_LEDS] = CHSV(150, 100, GLOBAL_BRIGHTNESS);
  }

  for(int i = 0; i < NUM_LEDS; i++) 
  {
    leds[i] = leds[i+1]; 
  } 
    FastLED.delay(60);
 }

//======================================================================

void random_march()
{  
 if(index < NUM_LEDS) {index++;}
 if(index >= NUM_LEDS-1) {index=0;} 
  leds[index-1] = CHSV(random(16,120), 255,GLOBAL_BRIGHTNESS);
  leds[index] = CRGB::White;
  FastLED.delay(2);
} 

//======================================================================

void candycane() 
{
  index++;
  int N3  = int(NUM_LEDS/3);
  int N6  = int(NUM_LEDS/6);  
  int N12 = int(NUM_LEDS/12);  
  for(int i = 0; i < N6; i++ ) {
    int j0 = (index + i + NUM_LEDS - N12) % NUM_LEDS;
    int j1 = (j0+N6) % NUM_LEDS;
    int j2 = (j1+N6) % NUM_LEDS;
    int j3 = (j2+N6) % NUM_LEDS;
    int j4 = (j3+N6) % NUM_LEDS;
    int j5 = (j4+N6) % NUM_LEDS;
    leds[j0] = CRGB(255, 255, 255).nscale8_video(GLOBAL_BRIGHTNESS);
    leds[j1] = CRGB(255, 0, 0).nscale8_video(GLOBAL_BRIGHTNESS);
    leds[j2] = CRGB(255, 255, 255).nscale8_video(GLOBAL_BRIGHTNESS);
    leds[j3] = CRGB(255, 0, 0).nscale8_video(GLOBAL_BRIGHTNESS);
    leds[j4] = CRGB(255, 255, 255).nscale8_video(GLOBAL_BRIGHTNESS);
    leds[j5] = CRGB(255, 0, 0).nscale8_video(GLOBAL_BRIGHTNESS);
  }
    FastLED.delay(60);
 }

//======================================================================

void RedGreenWhiteDot()
{
  int pos = beatsin16(3,2,NUM_LEDS-2);
  leds[pos+1] = CHSV(100,255,GLOBAL_BRIGHTNESS);          //trail Green
  leds[pos] = CHSV (130,0,GLOBAL_BRIGHTNESS);                       //dot  WHITE TO PALE YELLOW
  leds[pos-1] = CHSV(0,255,GLOBAL_BRIGHTNESS);          //trail Red
}

//===================================================================================================================================================

void GreenGreenWhiteDot()
{
  int pos = beatsin16(3,2,NUM_LEDS-2);
  leds[pos+1] = CHSV(90,255,GLOBAL_BRIGHTNESS);          //trail Green
  leds[pos] = CHSV (130,0, GLOBAL_BRIGHTNESS);                       //dot  WHITE TO PALE YELLOW
  leds[pos-1] = CHSV(120,255,GLOBAL_BRIGHTNESS);          //trail Light Green
}

//===================================================================================================================================================

void GreenBlueWhiteDot()
{
  int pos = beatsin16(3,2,NUM_LEDS-2);
  leds[pos+1] = CHSV(135,255,GLOBAL_BRIGHTNESS);          //trail Light Blue
  leds[pos] = CHSV (130,0,GLOBAL_BRIGHTNESS);                       //dot  WHITE TO PALE YELLOW
  leds[pos-1] = CHSV(115,255,GLOBAL_BRIGHTNESS);          //trail Light Green
}
//===================================================================================================================================================

void YellowGreenWhiteDot()
{ 
  int pos = beatsin16(3,2,NUM_LEDS-2);
  leds[pos+1] = CHSV(40,255,GLOBAL_BRIGHTNESS);          //trail Random Yellow
  leds[pos] = CHSV (130,0,GLOBAL_BRIGHTNESS);                       //dot  WHITE TO PALE YELLOW
  leds[pos-1] = CHSV(80,255,GLOBAL_BRIGHTNESS);          //trail Random Green
}

//===================================================================================================================================================

void chaserfadeRedGreenWhiteDot()  // OLD VERSION DOES NOT WORK WITH REMOTE PROPERLY SO NOT BEING USED
{   
  uint32_t irCode=0;               // TRIED A FIX....
  if (irCode >=1){return;}         // .... BUT NEEDS TESTING STILL...
  
  for(int dot=(NUM_LEDS-1) ; dot >=0 ; dot--){
  leds[dot-1] = CRGB::White;
  leds[dot] = CRGB::Red;
  fadeToBlackBy( leds, NUM_LEDS, 1);
  FastLED.delay(1000/fps*8);            
 }

  for(int dot = 0;dot < NUM_LEDS; dot++){
  leds[dot] = CRGB::White;
  leds[dot-1] = CRGB::Green;
  fadeToBlackBy( leds, NUM_LEDS, 0.1);
  FastLED.delay(1000/fps*8);            
 }
}

//======================================================================

void SilentNightRiderRedGreen()// OLD VERSION DOES NOT WORK WITH REMOTE PROPERLY SO NOT BEING USED
{ 
  uint32_t irCode=0;
  if (irCode >=1){return;} 

  for(int dot=(NUM_LEDS-1) ; dot >=0 ; dot--){
  leds[dot] = CRGB::Red;
  fadeToBlackBy( leds, NUM_LEDS, 1);
  FastLED.delay(1000/fps*8);            
}

  for(int dot = 0;dot < NUM_LEDS; dot++){ 
  leds[dot] = CRGB::Green;
  fadeToBlackBy( leds, NUM_LEDS, 0.1);
  FastLED.delay(1000/fps*8);            
 }
}

//======================================================================

void colorwipeRedGreen()// OLD VERSION DOES NOT WORK WITH REMOTE PROPERLY SO NOT BEING USED
{  
  uint32_t irCode=0;
  if (irCode >=1){return;} 

  for(int dot=(NUM_LEDS-1) ; dot >=0 ; dot--){ 
  leds[dot] = CRGB::Red;
  FastLED.delay(1000/fps*8);            
}

  for(int dot = 0;dot < NUM_LEDS; dot++){
  leds[dot] = CRGB::Green;
  FastLED.delay(1000/fps*8);            
 }
}

//===================================================================================================================================================

void fireStarter(){

 if(index < NUM_LEDS) {index++;}
 if(index >= NUM_LEDS-1) {leds[index] = leds[index-1]; index=0;} // take last index=0; off for a 1 shot comet (1 pass)
      
      ledh[index] = 64;                    // can be used to choose color 
  
      //The following lines create the fire starter effect
      thisbright = random((GLOBAL_BRIGHTNESS-5), (GLOBAL_BRIGHTNESS));// Randomly select a brightness between 50 and 100
      ledb[index] = thisbright;                          // Assign this random brightness value to the trailing LEDs
      addPixieDust(0);   // change to 1 for pulse 10 for neato pulse // Call the sparkle routine to create that sparkling effect. The potentiometer controls the difference in hue from LED to LED.
      leds[index] = (ledh[index],255,255); 
      leds[index] = CRGB::White;
//      leds[index] = CHSV (64,random(20,80), GLOBAL_BRIGHTNESS);  //dot  WHITE TO PALE YELLOW DOT
//  fadeToBlackBy( leds, NUM_LEDS, 200);
        FastLED.delay(1000/fps);                                  
}
//======================================================================

void pixieDustBackground1(){      //still needs that yellow trail between colors...??? how???

 if(index < NUM_LEDS) {index++;}
 if(index >= NUM_LEDS-1) {leds[index] = leds[index-1]; index=0;} // take last index=0; off for a 1 shot comet (1 pass)
 if(index<= 0) {thishue+=64;}

  ledh[index] = thishue;                    // can be used to choose color uncomment
     
        //The following lines create the fire starter effect
  thisbright = random((GLOBAL_BRIGHTNESS-5), (GLOBAL_BRIGHTNESS));// Randomly select a brightness between 50 and 100
  ledb[index] = thisbright;                          // Assign this random brightness value to the trailing LEDs
  sparkle(0);   // change to 1 for pulse 10 for neato pulse // Call the sparkle routine to create that sparkling effect. The potentiometer controls the difference in hue from LED to LED.
  leds[index] = (ledh[thishue],255,255); 
  leds[index] = CRGB::White;
//      leds[index] = CHSV (64,random(20,80), GLOBAL_BRIGHTNESS);  //dot  WHITE TO PALE YELLOW DOT
//   fadeLEDs(0.4);                                         // A low number creates a longer tail
    FastLED.delay(1000/fps);                                 
}
//======================================================================

void fireStarterGHUE_RAINBOW(){
 if(index < NUM_LEDS) {index++;}
 if(index >= NUM_LEDS-1) {leds[index] = leds[index-1]; index=0;} // take last index=0; off for a 1 shot comet (1 pass)

      ledh[index] = (gHue);                    // can be used to choose color uncomment
      
      //The following lines create the fire starter effect
      thisbright = random((GLOBAL_BRIGHTNESS-5), (GLOBAL_BRIGHTNESS));// Randomly select a brightness between 50 and 100
      ledb[index] = thisbright;                          // Assign this random brightness value to the trailing LEDs
      sparkle(0);   // change to 1 for pulse 10 for neato pulse // Call the sparkle routine to create that sparkling effect. The potentiometer controls the difference in hue from LED to LED.
      leds[index] = (ledh[gHue],255,255); 
      leds[index] = CRGB::White;
//      fadeLEDs(0.4);                                         // A low number creates a longer tail
        FastLED.delay(1000/fps);                                 
}
//======================================================================

void fireStarter_RAINBOW_PULSE_SLOW(){
 if(index < NUM_LEDS) {index++;}
 if(index >= NUM_LEDS-1) {leds[index] = leds[index-1]; index=0;} // take last index=0; off for a 1 shot comet (1 pass)
 
      ledh[index] = (ghue);                    // can be used to choose color uncomment

      //The following lines create the fire starter effect
      thisbright = random((GLOBAL_BRIGHTNESS-5), (GLOBAL_BRIGHTNESS));// Randomly select a brightness between 50 and 100
      ledb[index] = thisbright;                          // Assign this random brightness value to the trailing LEDs
      sparkle(0);   // change to 1 for slow pulse 10 for fast neato pulse 
                                                        // Call the sparkle routine to create that sparkling effect. 
                                                         //The index (or could be gHue) controls the difference in hue from LED to LED.
      leds[index] = (ledh[ghue],255,255); 
      leds[index] = CRGB::White;
//      fadeLEDs(0.4);                                         // A low number creates a longer tail
        FastLED.delay(1000/fps);                                 
}

//======================================================================

void fireStarter_YELLOW_GREEN(){
 if(index < NUM_LEDS) {index++;}
 if(index >= NUM_LEDS-1) {leds[index] = leds[index-1]; index=0;} // take last index=0; off for a 1 shot comet (1 pass)
 
      ledh[index] = 64;                    // can be used to choose color uncomment

      //The following lines create the fire starter effect
      thisbright = random((GLOBAL_BRIGHTNESS-5), (GLOBAL_BRIGHTNESS));// Randomly select a brightness between 50 and 100
      ledb[index] = thisbright;                          // Assign this random brightness value to the trailing LEDs
      sparkle(1);   // change to 1 for slow pulse 10 for fast neato pulse 
                                                         // Call the sparkle routine to create that sparkling effect. 
                                                         //The index (or could be gHue) controls the difference in hue from LED to LED.
      leds[index] = (ledh[index],255,255); 
      leds[index] = CRGB::White;
//      fadeLEDs(0.4);                                         // A low number creates a longer tail
        FastLED.delay(1000/fps);                                  
}

//===================================================================================================================================================
// sparkle() : is used by the fireStarter routine to create a sparkling/fire-like effect
//             Each LED hue and brightness is monitored and modified using arrays  (ledh[]  and ledb[])
//===================================================================================================================================================
void sparkle(byte hDiff){

  for(int i = 0; i < NUM_LEDS; i++) {
    ledh[i] = ledh[i] + hDiff;                // hDiff controls the extent to which the hue changes along the trailing LEDs
    
    // This will prevent "negative" brightness.
    if(ledb[i]<255-17){
      ledb[i]=255-20;

    }
    
    // The probability of "re-igniting" an LED will decrease as you move along the tail
    // Once the brightness reaches zero, it cannot be re-ignited unless the leading LED passes over it again.
    if(ledb[i]>255-20){
      ledb[i]=ledb[i]-2;
      sparkTest = random(0,GLOBAL_BRIGHTNESS);
      if(sparkTest>(GLOBAL_BRIGHTNESS-(ledb[i]/1.1))){
        ledb[i] = GLOBAL_BRIGHTNESS;
      } else {
        ledb[i] = ledb[i] / 2;                 
      }
    }
    leds[i] = CHSV(ledh[i],255,ledb[i]);   
  }
//  addGlitter(GLITTER_AMOUNT/2);
}

//===================================================================================================================================================
void addPixieDust(byte hDiff){

  for(int i = 0; i < NUM_LEDS; i++) {
    ledh[i] = ledh[i] + hDiff;                // hDiff controls the extent to which the hue changes along the trailing LEDs
    
    // This will prevent "negative" brightness.
    if(ledb[i]<3){
      ledb[i]=0;

    }
    
    // The probability of "re-igniting" an LED will decrease as you move along the tail
    // Once the brightness reaches zero, it cannot be re-ignited unless the leading LED passes over it again.
    if(ledb[i]>0){
      ledb[i]=ledb[i]-2;
      sparkTest = random(0,GLOBAL_BRIGHTNESS);
      if(sparkTest>(GLOBAL_BRIGHTNESS-(ledb[i]/1.1))){
        ledb[i] = GLOBAL_BRIGHTNESS;
      } else {
        ledb[i] = ledb[i] / 2;   //was 2               
        
      }
    }
    leds[i] = CHSV(ledh[i],255,ledb[i]);   
  }
//  addGlitter(GLITTER_AMOUNT/2);
}

//===================================================================================================================================================

void cometEffect()
{
 if(index < NUM_LEDS) {index++;}
 if(index >= NUM_LEDS-1) {leds[index] = leds[index-1]; index=0;} // take last index=0; off for a 1 shot comet (1 pass)
  leds[index] = CHSV(64,255,GLOBAL_BRIGHTNESS);                  //trail
    
    //  leds[index] = CHSV(gHue*10,random16(0,60),random16((GLOBAL_BRIGHTNESS/3),(GLOBAL_BRIGHTNESS)));          //trail RAINBOW++
  fadeLEDs(4);
  FastLED.delay(1000/fps*2);
}

//===================================================================================================================================================

void cometEffectSinelonGHUE_SLOW_RAINBOW()
{
//  fadeToBlackBy( leds, NUM_LEDS, FADEOUT_SPEED/32);

 int pos = beatsin16(3,2,NUM_LEDS-2);
  
//  leds[pos] += CHSV( gHue, 255, 255);
  leds[pos+1] = CHSV(ghue,random16(200,255),GLOBAL_BRIGHTNESS);          //trail RAINBOW++
  leds[pos] = CHSV (130,0, GLOBAL_BRIGHTNESS);                       //dot  WHITE TO PALE YELLOW
  leds[pos-1] = CHSV(ghue,random16(200,255),GLOBAL_BRIGHTNESS);          //trail RAINBOW++

//  leds[index] = CHSV (random(64, 86), random(0, 50), random16((GLOBAL_BRIGHTNESS/3),(GLOBAL_BRIGHTNESS))); //trail YELLOW TO LIGHT GREEN   
  fadeLEDs(3);
//  FastLED.delay(1000/fps*2);
}
//===================================================================================================================================================

void cometChaserRAINBOW()
{ 
 if(index < NUM_LEDS) {index++;}              
 if(index >= NUM_LEDS-1) {leds[index] = leds[index-1]; index=0;} // take last index=0; off for a 1 shot comet (1 pass)

  leds[index+1] = CHSV (130,0,GLOBAL_BRIGHTNESS);                       //dot  WHITE TO PALE YELLOW
  leds[index] = CHSV(gHue,random16(200,255),GLOBAL_BRIGHTNESS);//trail RAINBOW++
  fadeLEDs(4);
  FastLED.delay(1000/fps*2);
}
//===================================================================================================================================================

void cometChaserAQUA()
{ 
 if(index < NUM_LEDS) {index++;}              
 if(index >= NUM_LEDS-1) {leds[index] = leds[index-1]; index=0;} // take last index=0; off for a 1 shot comet (1 pass)

  leds[index+1] = CHSV (130,0, GLOBAL_BRIGHTNESS);                       //dot  WHITE TO PALE YELLOW
  leds[index] = CHSV(random16(128,135),random16(100,255),GLOBAL_BRIGHTNESS);   //trail AQUA TO LIGHT BLUE
  fadeLEDs(4);
  FastLED.delay(1000/fps*2);
}
//===================================================================================================================================================

void cometChaserYELLOW_GREEN()
{ 
 if(index < NUM_LEDS) {index++;}              
 if(index >= NUM_LEDS-1) {leds[index] = leds[index-1]; index=0;} // take last index=0; off for a 1 shot comet (1 pass)

  leds[index+1] = CHSV (64,30, GLOBAL_BRIGHTNESS);                       //dot  WHITE TO PALE YELLOW
  leds[index] = CHSV (random(64, 86), random(100, 255), GLOBAL_BRIGHTNESS);   //trail YELLOW TO LIGHT GREEN   
  fadeLEDs(4);
  FastLED.delay(1000/fps*2);
}

//===================================================================================================================================================

void fadeLEDs(int fadeVal){              // used for cometChaser
  for (int i = 0; i<NUM_LEDS; i++){
    leds[i].fadeToBlackBy(fadeVal/4);
  }
}

//===================================================================================================================================================

void meteorRain()
{               
 // meteorRain - Color (red, green, blue), meteor size, trail decay, random trail decay (true/false), speed delay
 meteorRain(0xff,0xff,0xff, 2, 20, true); 
                                               //  20 for testing 100 leds / 10 for 200 leds?
}               
void meteorRain(byte red, byte green, byte blue, byte meteorSize, byte meteorTrailDecay, boolean meteorRandomDecay) {  
  setAll(0,0,0);
 
  for(int i = 0; i < NUM_LEDS+NUM_LEDS; i++) {
   
   
    // fade brightness all LEDs one step
    for(int j=0; j<NUM_LEDS; j++) {
      if( (!meteorRandomDecay) || (random(10)>5) ) {
        fadeToBlack(j, meteorTrailDecay );        
      }
    }
   
    // draw meteor
    for(int j = 0; j < meteorSize; j++) {
      if( ( i-j <NUM_LEDS) && (i-j>=0) ) {
        setPixel(i-j, red, green, blue);
      }
    }
   
    showStrip();
  FastLED.delay(1000/fps*2);
  }
}

// used by meteorrain
void fadeToBlack(int ledNo, byte fadeValue) {
   leds[ledNo].fadeToBlackBy( fadeValue );
}

//======================================================================
  
  void NewKITT_ALL()
  {
  RightToLeft(0, 0xff, 0, 50, 25, 0);
  LeftToRight(0, 0xff, 0, 50, 25, 0);
  }

// used by NewKITT
void LeftToRight(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay) {
  for(int i = 0; i < NUM_LEDS-EyeSize-2; i++) {
    setAll(0,0,0);
    setPixel(i, red/10, green/10, blue/10);
    for(int j = 1; j <= EyeSize; j++) {
      setPixel(i+j, red, green, blue);
    }
    
    setPixel(i+EyeSize+1, red/10, green/10, blue/10);
    showStrip();
      FastLED.delay(SpeedDelay);
  }
    FastLED.delay(ReturnDelay);
}

// used by NewKITT
void RightToLeft(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay) {
  for(int i = NUM_LEDS-EyeSize-2; i > 0; i--) {
    setAll(0,0,0);
    setPixel(i, red/10, green/10, blue/10);
    for(int j = 1; j <= EyeSize; j++) {
      setPixel(i+j, red, green, blue);
    }
    setPixel(i+EyeSize+1, red/10, green/10, blue/10);
    showStrip();
      FastLED.delay(SpeedDelay);
  }
    FastLED.delay(ReturnDelay);
}


//======================================================================

void showLED(int pos, int thishue, int thissat, int GLOBAL_BRIGHTNESS)
{
  leds[pos] = CHSV (thishue, thissat, GLOBAL_BRIGHTNESS);
   FastLED.show();
}
//======================================================================

void showStrip() 
{
   FastLED.show();
}
//======================================================================

void setPixel(int Pixel, byte red, byte green, byte blue) {
   leds[Pixel].r = red;
   leds[Pixel].g = green;
   leds[Pixel].b = blue;
}
//======================================================================

void setAll(byte red, byte green, byte blue) {
  for(int i = 0; i < NUM_LEDS; i++ ) {
    setPixel(i, red, green, blue);
  }
}
//======================================================================
//======================================================================

//*Animations End*