Pixel LED matrix using WS2812

Hai,
Please help me to following code use For /while condition to make code easy.
this is pixel led (8x6) matrix with simple animation with 8 frames. so i f need to use 1000 of frame this cording is not easy under void Loop and Void Render Frame.

so my requirement is this code simplify by advance coding technics like for, while
pixel frame binary code canot change need to simplify void loop and renderframe

#include <Adafruit_NeoPixel.h>

#define PIN 8
#define NUMLED 48
#define Wait 100

uint32_t ledarray_01[] = {
                       0x00000000, 0x000000FF, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 
                       0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0000FF00, 0x00000000, 
                       0x00000000, 0x000000FF, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 
                       0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0000FF00, 0x00000000, 
                       0x00000000, 0x000000FF, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 
                       0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0000FF00, 0x00000000,
                       };
uint32_t ledarray_02[] = {
                       0x00000000, 0x00000000, 0x000000FF, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 
                       0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0000FF00, 0x00000000, 0x00000000, 
                       0x00000000, 0x00000000, 0x000000FF, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 
                       0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0000FF00, 0x00000000, 0x00000000, 
                       0x00000000, 0x00000000, 0x000000FF, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 
                       0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0000FF00, 0x00000000, 0x00000000,
                       };
uint32_t ledarray_03[] = {
                       0x00000000, 0x00000000, 0x00000000, 0x000000FF, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 
                       0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0000FF00, 0x00000000, 0x00000000, 0x00000000, 
                       0x00000000, 0x00000000, 0x00000000, 0x000000FF, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 
                       0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0000FF00, 0x00000000, 0x00000000, 0x00000000, 
                       0x00000000, 0x00000000, 0x00000000, 0x000000FF, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 
                       0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0000FF00, 0x00000000, 0x00000000, 0x00000000,
                       };
uint32_t ledarray_04[] = {
                      0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x000000FF, 0x00000000, 0x00000000, 0x00000000, 
                       0x00000000, 0x00000000, 0x00000000, 0x0000FF00, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 
                       0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x000000FF, 0x00000000, 0x00000000, 0x00000000, 
                       0x00000000, 0x00000000, 0x00000000, 0x0000FF00, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 
                       0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x000000FF, 0x00000000, 0x00000000, 0x00000000, 
                       0x00000000, 0x00000000, 0x00000000, 0x0000FF00, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
                       };
uint32_t ledarray_05[] = {
                       0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x000000FF, 0x00000000, 0x00000000, 
                       0x00000000, 0x00000000, 0x0000FF00, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 
                       0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x000000FF, 0x00000000, 0x00000000, 
                       0x00000000, 0x00000000, 0x0000FF00, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 
                       0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x000000FF, 0x00000000, 0x00000000, 
                       0x00000000, 0x00000000, 0x0000FF00, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
                       };                       
uint32_t ledarray_06[] = {
                       0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x000000FF, 0x00000000, 
                       0x00000000, 0x0000FF00, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 
                       0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x000000FF, 0x00000000, 
                       0x00000000, 0x0000FF00, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 
                       0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x000000FF, 0x00000000, 
                       0x00000000, 0x0000FF00, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
                       };

uint32_t ledarray_07[] = {
                       0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x000000FF, 
                       0x0000FF00, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 
                       0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x000000FF, 
                       0x0000FF00, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 
                       0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x000000FF, 
                       0x0000FF00, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
                       };
uint32_t ledarray_08[] = {
                       0x000000FF, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 
                       0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0000FF00, 
                       0x000000FF, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 
                       0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0000FF00, 
                       0x000000FF, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 
                       0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0000FF00, 
                       };

                       
                       
// Parameter 1 = number of pixels in strip
// Parameter 2 = pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
//   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
//   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
//   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
//   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUMLED, D8, NEO_GRB + NEO_KHZ800);

void setup(){
  pinMode(D8, OUTPUT);
  strip.begin();
  strip.setBrightness(60);
  strip.show();   // Initialize all pixels to 'off'
  
  
}

void loop(){                         // this is what i need to simplify 
RenderFrame_01();
delay(100);

RenderFrame_02(); 
delay(100);
RenderFrame_03(); 
delay(100);
RenderFrame_04(); 
delay(100);
RenderFrame_05();
delay(100); 
RenderFrame_06(); 
delay(100);
RenderFrame_07();
delay(100); 
RenderFrame_08();
delay(100);  
 
}

void RenderFrame_01(){                                      // this is what i need to simplify 
  for (uint16_t t = 0; t < NUMLED; t++){
  strip.setPixelColor(t, ledarray_01[t]);
  }
  strip.show();
}

void RenderFrame_02(){
  for (uint16_t t = 0; t < NUMLED; t++){
  strip.setPixelColor(t, ledarray_02[t]);
  }
  strip.show();
}

void RenderFrame_03(){
  for (uint16_t t = 0; t < NUMLED; t++){
  strip.setPixelColor(t, ledarray_03[t]);
  }
  strip.show();
}

void RenderFrame_04(){
  for (uint16_t t = 0; t < NUMLED; t++){
  strip.setPixelColor(t, ledarray_04[t]);
  }
  strip.show();
}

void RenderFrame_05(){
  for (uint16_t t = 0; t < NUMLED; t++){
  strip.setPixelColor(t, ledarray_05[t]);
  }
  strip.show();
}

void RenderFrame_06(){
  for (uint16_t t = 0; t < NUMLED; t++){
  strip.setPixelColor(t, ledarray_06[t]);
  }
  strip.show();
}

void RenderFrame_07(){
  for (uint16_t t = 0; t < NUMLED; t++){
  strip.setPixelColor(t, ledarray_07[t]);
  }
  strip.show();
}

void RenderFrame_08(){
  for (uint16_t t = 0; t < NUMLED; t++){
  strip.setPixelColor(t, ledarray_08[t]);
  }
  strip.show();
}

Find these two "D8" and change them to "PIN"... or rename "PIN" to "D8" and your project works!
dots

Code is working Fine Dear. My requirement if simplify the code under Void loop and Void RenderFrame_01_02_03_...................1000 because of if 1000 of frame use my coding is repeating 1000 times

Not unless you change PIN or D8.

why need to change D8 as PIN dear

The minor change will make your broken sketch compile.

This code is working 100%

You are 100% wrong.

sketch.ino:82:53: error: 'D8' was not declared in this scope
 Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUMLED, D8, NEO_GRB + NEO_KHZ800);
                                                     ^~
sketch.ino:82:53: note: suggested alternative: 'u8'
 Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUMLED, D8, NEO_GRB + NEO_KHZ800);
                                                     ^~
                                                     u8
sketch.ino: In function 'void setup()':
sketch.ino:85:11: error: 'D8' was not declared in this scope
   pinMode(D8, OUTPUT);
           ^~
sketch.ino:85:11: note: suggested alternative: 'u8'
   pinMode(D8, OUTPUT);
           ^~
           u8

Error during build: exit status 1

I am 100% right.
dots

I need to simplify this RenderFrame_01 again 02 again 03 like up to 1000 using for loop

You need to read post #2 and repost your sketch with the corrections.

What is the bode you selected This is ESP8266

...

The corrected code (from corrections noted in Post #2) runs the same on Nano and ESP8266.

ok its corrected. so can i simplify the void RenderFrame_01...02...03...up to 1000

Yes, you can simplify your sketch. You can add a counter to cycle through the eight frames as many times as you want.

I used your arrays and 8 lines of void loop()... total lines, 35.

Post your corrected sketch.

Here is the compile output for ESP8266 of the corrected sketch:

. Variables and constants in RAM (global, static), used 29664 / 80192 bytes (36%)
║   SEGMENT  BYTES    DESCRIPTION
╠══ DATA     3032     initialized variables
╠══ RODATA   920      constants       
╚══ BSS      25712    zeroed variables
. Instruction RAM (IRAM_ATTR, ICACHE_RAM_ATTR), used 59819 / 65536 bytes (91%)
║   SEGMENT  BYTES    DESCRIPTION
╠══ ICACHE   32768    reserved space for flash instruction cache
╚══ IRAM     27051    code in IRAM    
. Code in flash (default, ICACHE_FLASH_ATTR), used 233092 / 1048576 bytes (22%)
║   SEGMENT  BYTES    DESCRIPTION
╚══ IROM     233092   code in flash   

And this report is for the Nano:

Sketch uses 4460 bytes (14%) of program storage space. Maximum is 30720 bytes.
Global variables use 1577 bytes (77%) of dynamic memory, leaving 471 bytes for local variables. Maximum is 2048 bytes.

(a lot of the dynamic memory is used due to arrays for the LEDs)

hi @manojkb welcome to the forum.

Even if you were only turning on and off 48 pixels, and coded that as efficiently as you could, a frame would take 6 bytes, 1000 frames 6000 bytes.

If you used a color lookup table of, say, 16 colors, you'd need 24000 bytes.

If you have to have general complete control of every pixel every frame.

Is there anything about your intended animation that would make more sense as a computable frame, like a car moving across a screen or scrolling text or two dinosaurs battling over an Oreo?

These can be programmed not by specifying every pixel of every frame, instead by have objects that had characteristics like speed and position and shape that you could compute on the fly.

Obvsly your current code, even if memory isn't showstopper, is a nightmare that cannot reasonably be used as the basis for doing 1000 frames.

Anything beyond your current approach will need more than a little help, and may not be a good place to be banging your head until you've picked ip a bit more programming skill.

a7

The WS2812 matrix you have is different from the matrix I am simulating. You can see the pattern of my simulation, it is different from the pattern of your code.

My code is memory going high? so what can do dear. any other coding system please help me

Post your corrected sketch.

#include <Adafruit_NeoPixel.h>


#define NUMLED 48
#define Wait 100


const long ledarray0[] PROGMEM = {
				0x00000000, 0x00FF0000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 
				0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00FF0000, 0x00000000, 
				0x00000000, 0x00FF0000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 
				0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00FF0000, 0x00000000, 
				0x00000000, 0x00FF0000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 
				0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00FF0000, 0x00000000, 
};

const long ledarray1[] PROGMEM = {
				0x00000000, 0x00000000, 0x00FF0000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 
				0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00FF0000, 0x00000000, 0x00000000, 
				0x00000000, 0x00000000, 0x00FF0000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 
				0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00FF0000, 0x00000000, 0x00000000, 
				0x00000000, 0x00000000, 0x00FF0000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 
				0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00FF0000, 0x00000000, 0x00000000, 
};

const long ledarray2[] PROGMEM = {
				0x00000000, 0x00000000, 0x00000000, 0x00FF0000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 
				0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00FF0000, 0x00000000, 0x00000000, 0x00000000, 
				0x00000000, 0x00000000, 0x00000000, 0x00FF0000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 
				0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00FF0000, 0x00000000, 0x00000000, 0x00000000, 
				0x00000000, 0x00000000, 0x00000000, 0x00FF0000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 
				0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00FF0000, 0x00000000, 0x00000000, 0x00000000, 
};

const long ledarray3[] PROGMEM = {
				0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00FF0000, 0x00000000, 0x00000000, 0x00000000, 
				0x00000000, 0x00000000, 0x00000000, 0x00FF0000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 
				0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00FF0000, 0x00000000, 0x00000000, 0x00000000, 
				0x00000000, 0x00000000, 0x00000000, 0x00FF0000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 
				0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00FF0000, 0x00000000, 0x00000000, 0x00000000, 
				0x00000000, 0x00000000, 0x00000000, 0x00FF0000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 
};

const long ledarray4[] PROGMEM = {
				0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00FF0000, 0x00000000, 0x00000000, 
				0x00000000, 0x00000000, 0x00FF0000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 
				0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00FF0000, 0x00000000, 0x00000000, 
				0x00000000, 0x00000000, 0x00FF0000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 
				0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00FF0000, 0x00000000, 0x00000000, 
				0x00000000, 0x00000000, 0x00FF0000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 
};

const long ledarray5[] PROGMEM = {
				0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00FF0000, 0x00000000, 
				0x00000000, 0x00FF0000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 
				0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00FF0000, 0x00000000, 
				0x00000000, 0x00FF0000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 
				0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00FF0000, 0x00000000, 
				0x00000000, 0x00FF0000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 
};

const long ledarray6[] PROGMEM = {
				0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00FF0000, 
				0x00FF0000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 
				0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00FF0000, 
				0x00FF0000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 
				0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00FF0000, 
				0x00FF0000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 
};

const long ledarray7[] PROGMEM = {
				0x00FF0000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 
				0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00FF0000, 
				0x00FF0000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 
				0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00FF0000, 
				0x00FF0000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 
				0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00FF0000, 
};
                      
                       
// Parameter 1 = number of pixels in strip
// Parameter 2 = pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
//   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
//   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
//   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
//   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUMLED, D8, NEO_GRB + NEO_KHZ800);

void setup(){
  pinMode(D8, OUTPUT);
  strip.begin();
  strip.setBrightness(60);
  strip.show();   // Initialize all pixels to 'off'
  
  
}

void loop(){
RenderFrame_01();
delay(100);

RenderFrame_02(); 
delay(100);
RenderFrame_03(); 
delay(100);
RenderFrame_04(); 
delay(100);
RenderFrame_05();
delay(100); 
RenderFrame_06(); 
delay(100);
RenderFrame_07();
delay(100); 
RenderFrame_08();
delay(100);  
 
}

void RenderFrame_01(){
  for (uint16_t t = 0; t < NUMLED; t++){
  strip.setPixelColor(t, ledarray0[t]);
  }
  strip.show();
}

void RenderFrame_02(){
  for (uint16_t t = 0; t < NUMLED; t++){
  strip.setPixelColor(t, ledarray1[t]);
  }
  strip.show();
}

void RenderFrame_03(){
  for (uint16_t t = 0; t < NUMLED; t++){
  strip.setPixelColor(t, ledarray2[t]);
  }
  strip.show();
}

void RenderFrame_04(){
  for (uint16_t t = 0; t < NUMLED; t++){
  strip.setPixelColor(t, ledarray3[t]);
  }
  strip.show();
}

void RenderFrame_05(){
  for (uint16_t t = 0; t < NUMLED; t++){
  strip.setPixelColor(t, ledarray4[t]);
  }
  strip.show();
}

void RenderFrame_06(){
  for (uint16_t t = 0; t < NUMLED; t++){
  strip.setPixelColor(t, ledarray5[t]);
  }
  strip.show();
}

void RenderFrame_07(){
  for (uint16_t t = 0; t < NUMLED; t++){
  strip.setPixelColor(t, ledarray6[t]);
  }
  strip.show();
}

void RenderFrame_08(){
  for (uint16_t t = 0; t < NUMLED; t++){
  strip.setPixelColor(t, ledarray7[t]);
  }
  strip.show();
}


Declaring the arrays as const should fix that.

I think what the OP is wanting is a simpler way to cycle through the frames. Declaring a two-dimension array greatly simplified the code.
< edit - code removed >