/*****************************************
यह उदाहरण रंगों के 'पैलेट' को सेट करने और उपयोग करने के कई तरीके दिखाता है
FastLED के साथ।
//
ये कॉम्पैक्ट पैलेट आपके पुन: रंग को फिर से रंगने का एक आसान तरीका प्रदान करते हैं
फ्लाई पर एनीमेशन, जल्दी, आसानी से, और कम ओवरहेड के साथ।
//
पैलेट का उपयोग सिद्धांत की तुलना में व्यवहार में बहुत सरल है, इसलिए पहले बस
इस स्केच को चलाएं, और सुंदर रोशनी देखें जैसा कि आप तब पढ़ते हैं
कोड.  हालांकि इस स्केच में आठ (या अधिक) अलग-अलग रंग योजनाएं हैं,
पूरा स्केच एवीआर पर लगभग 6.5K तक संकलित होता है।
//
FastLED कुछ पूर्व-कॉन्फ़िगर किए गए रंग पैलेट प्रदान करता है, और इसे बनाता है
पैलेट के साथ अपनी खुद की रंग योजनाएं बनाना बेहद आसान है।
//
के अधिक अमूर्त 'सिद्धांत और व्यवहार' पर कुछ नोट्स
यह उदाहरण दिखाता है कि स्थिर रंग पैलेट कैसे सेट करें
जो PROGMEM (फ्लैश) में संग्रहीत किया जाता है, जो लगभग हमेशा अधिक होता है
RAM की तुलना में भरपूर।  इस तरह का एक स्थिर PROGMEM पैलेट
फ्लैश के 64 बाइट्स लेता है।
फास्टएलईडी कॉम्पैक्ट पैलेट पर अतिरिक्त नोट्स:
//
आम तौर पर, कंप्यूटर ग्राफिक्स में, पैलेट (या "रंग लुकअप टेबल")
इसमें 256 प्रविष्टियां हैं, जिनमें से प्रत्येक में एक विशिष्ट 24-बिट आरजीबी रंग है।  तब आप कर सकते हैं
एक साधारण 8-बिट (एक बाइट) मान का उपयोग करके रंग पैलेट में इंडेक्स करें।
एक 256-एंट्री कलर पैलेट 768 बाइट्स रैम लेता है, जो Arduino पर है
यह संभवतः "बहुत अधिक" बाइट्स है।
//
FastLED पारंपरिक 256-तत्व पैलेट प्रदान करता है, सेटअप के लिए जो
रैम में 768-बाइट लागत वहन कर सकते हैं।
//
हालांकि, फास्टएलईडी एक कॉम्पैक्ट विकल्प भी प्रदान करता है।  FastLED ऑफ़र
पैलेट जो 16 अलग-अलग प्रविष्टियों को संग्रहीत करते हैं, लेकिन इसे ASIF के रूप में एक्सेस किया जा सकता है
उनके पास वास्तव में 256 प्रविष्टियां हैं; यह इंटरपोलिंग द्वारा पूरा किया जाता है
पंद्रह मध्यवर्ती पैलेट बनाने के लिए 16 स्पष्ट प्रविष्टियों के बीच
प्रत्येक जोड़ी के बीच प्रविष्टियां।
//






*******************************************/
#include <FastLED.h>
//num of rgbled in matrix      plus 
#define LED_PIN     3
#define NUM_LEDS   290//   matrix led plus rgb lrds ina ring 
#define BRIGHTNESS  90
#define LED_TYPE    WS2811
#define COLOR_ORDER GRB
CRGB leds[NUM_LEDS];

#define UPDATES_PER_SECOND 300




CRGBPalette16 currentPalette;
TBlendType    currentBlending;

extern CRGBPalette16 myRedWhiteBluePalette;
extern const TProgmemPalette16 myRedWhiteBluePalette_p PROGMEM;


void setup() {
    FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
    FastLED.setBrightness(  BRIGHTNESS );

    currentPalette = RainbowColors_p;
    currentBlending = LINEARBLEND;
}


void loop()
{
    ChangePalettePeriodically();

    static uint8_t startIndex = 0;
    startIndex = startIndex + 1; /* motion speed */

    FillLEDsFromPaletteColors( startIndex);

    FastLED.show();
    FastLED.delay(1000 / UPDATES_PER_SECOND);
}

void FillLEDsFromPaletteColors( uint8_t colorIndex)
{
    uint8_t brightness = 255;

    for( int i = 0; i < NUM_LEDS; i++) {
        leds[i] = ColorFromPalette( currentPalette, colorIndex, brightness, currentBlending);
        colorIndex += 3;
    }
}


// There are several different palettes of colors demonstrated here.
//
// FastLED provides several 'preset' palettes: RainbowColors_p, RainbowStripeColors_p,
// OceanColors_p, CloudColors_p, LavaColors_p, ForestColors_p, and PartyColors_p.
//
// Additionally, you can manually define your own color palettes, or you can write
// code that creates color palettes on the fly.  All are shown here.

void ChangePalettePeriodically()
{
    uint8_t secondHand = (millis() / 1000) % 60;
    static uint8_t lastSecond = 99;

    if( lastSecond != secondHand) {
        lastSecond = secondHand;
        if( secondHand ==  0)  { currentPalette = RainbowColors_p;         currentBlending = LINEARBLEND; }
        if( secondHand == 10)  { currentPalette = RainbowStripeColors_p;   currentBlending = NOBLEND;  }
        if( secondHand == 15)  { currentPalette = RainbowStripeColors_p;   currentBlending = LINEARBLEND; }
        if( secondHand == 20)  { SetupPurpleAndGreenPalette();             currentBlending = LINEARBLEND; }
        if( secondHand == 25)  { SetupTotallyRandomPalette();              currentBlending = LINEARBLEND; }
        if( secondHand == 30)  { SetupBlackAndWhiteStripedPalette();       currentBlending = NOBLEND; }
        if( secondHand == 35)  { SetupBlackAndWhiteStripedPalette();       currentBlending = LINEARBLEND; }
        if( secondHand == 40)  { currentPalette = CloudColors_p;           currentBlending = LINEARBLEND; }
        if( secondHand == 45)  { currentPalette = PartyColors_p;           currentBlending = LINEARBLEND; }
        if( secondHand == 50)  { currentPalette = myRedWhiteBluePalette_p; currentBlending = NOBLEND;  }
        if( secondHand == 55)  { currentPalette = myRedWhiteBluePalette_p; currentBlending = LINEARBLEND; }
    }
}

// This function fills the palette with totally random colors.
void SetupTotallyRandomPalette()
{
    for( int i = 0; i < 16; i++) {
        currentPalette[i] = CHSV( random8(), 255, random8());
    }
}

// This function sets up a palette of black and white stripes,
// using code.  Since the palette is effectively an array of
// sixteen CRGB colors, the various fill_* functions can be used
// to set them up.
void SetupBlackAndWhiteStripedPalette()
{
    // 'black out' all 16 palette entries...
    fill_solid( currentPalette, 16, CRGB::Black);
    // and set every fourth one to white.
    currentPalette[0] = CRGB::White;
    currentPalette[4] = CRGB::White;
    currentPalette[8] = CRGB::White;
    currentPalette[12] = CRGB::White;

}

// This function sets up a palette of purple and green stripes.
void SetupPurpleAndGreenPalette()
{
    CRGB purple = CHSV( HUE_PURPLE, 255, 255);
    CRGB green  = CHSV( HUE_GREEN, 255, 255);
    CRGB black  = CRGB::Black;

    currentPalette = CRGBPalette16(
                                   green,  green,  black,  black,
                                   purple, purple, black,  black,
                                   green,  green,  black,  black,
                                   purple, purple, black,  black );
}




// This example shows how to set up a static color palette
// which is stored in PROGMEM (flash), which is almost always more
// plentiful than RAM.  A static PROGMEM palette like this
// takes up 64 bytes of flash.
const TProgmemPalette16 myRedWhiteBluePalette_p PROGMEM =
{
    CRGB::Red,
    CRGB::Yellow, // 'white' is too bright compared to red and blue
    CRGB::Blue,
    CRGB::Black,

    CRGB::Red,
    CRGB::Gray,
    CRGB::Blue,
    CRGB::Black,

    CRGB::Red,
    CRGB::Red,
    CRGB::Yellow,
    CRGB::Gray,
    
    CRGB::Blue,
    CRGB::Green,
    CRGB::Yellow,
    CRGB::Gray,
    

};



FPS: 0
Power: 0.00W