How to save led array to restore at a later time

I would like to store the current state of the FastLED array to restore after clearing and displaying all leds (i.e. prove that all leds are working, then go back to the original colors).

Any help would be greatly appreciated.

Thanks!

example code below:

#include <FastLED.h>

#define LED_TYPE WS2812B // type of RGB LEDs
#define COLOR_ORDER GRB // sequence of colors in data stream
#define NUM_LEDS 96 //
#define DATA_PIN 2 // LED data pin
#define BRIGHTNESS 75 // brightness range [off..on] = [0..255]
CRGB leds[NUM_LEDS];
void setup() {

FastLED.addLeds<LED_TYPE, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS);
FastLED.setBrightness(BRIGHTNESS);
}
void loop() {
FastLED.clear(); // clear all led info
FastLED.show(); // all LEDs off now
delay(1000);
leds[1]=CRGB::Maroon;
leds[2]=CRGB::DarkGreen;
leds[3]=CRGB::Coral;
leds[4]=CRGB::DeepPink;
leds[5]=CRGB::DodgerBlue;
leds[6]=CRGB::Goldenrod;
FastLED.show();
delay(1000);
// how do you save the current Colors of the LEDs?

fill_solid(leds, NUM_LEDS,CRGB::Khaki); // turn on all Leds
FastLED.show();
delay(1000);
// how do you restore Leds color prior to the Khaki fill??

}

If you want to save the color of all individual leds then you could copy the whole CRGB array (leds) , this would take nearly 300 bytes. Since you are only defining 6 of them you could also copy just that part (why aren't you lighting up led nr. 0 ? ) or you could just create a small function that fills them up and call that.

I'm just skipping leds[0] for now, the remainder leds are somewhat randomly turned to a particular color. The first 6 leds are just used for an example in this code.

So, I've tried the following prior to the Khaki fill.

for (x=1; x<=NUM_LEDS;x++){
backup_leds[x]=leds[x];
}

and then after, the reverse

for (x=1; x<=NUM_LEDS;x++){
leds[x]=backup_leds[x];
}
FastLED.show();


This didn't appear to work, what am I missing here?

Thanks!

Cannot tell what you did wrong from the posted code, too much missing and the lack of code tags corrupts the text. When using a for loop you need to copy one array element at a time, and the array index always starts with 0, so that a 96 element array is numbered from 0 through 95.

  for (int x = 0; x < NUM_LEDS; x++) {
    backup_leds[x] = leds[x];
  }

Much easier and faster to use memcpy() to copy the data back and forth, just make sure backup_leds is the same size as leds

//create an array to store the backup copy of leds
CRGB backup_leds[NUM_LEDS];

//save current leds array to backup_leds
memcpy(backup_leds, leds, sizeof(leds));

//restore leds from backup_leds
memcpy(leds, backup_leds, sizeof(leds));