256 RGB Matrix with fastled

Hi all

this is my first post.
I have somme troubles to make my code smaller.

i have a matrix 32*8 controlled by fastled library.
the codes works but i want it to be smaller because i repeat a lot of times the same code exept the name

as example

void LEDMATRIX() {
  // Frame 1
  FastLED.clear();
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = pgm_read_dword(&(Xmas001[i]));
  }
  FastLED.show();
  delay(400);

  // Frame 2
  FastLED.clear();
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = pgm_read_dword(&(Xmas002[i]));
  }

i want to make the Xmas.... dynamic

i got in mind to do this with a array

char* Xitems [77] = {
  "Xmas001" , "Xmas002" , "Xmas003" , "Xmas004" , "Xmas005" , "Xmas006" , "Xmas007" , "Xmas008" , "Xmas009" , "Xmas010" , "Xmas011" , "Xmas012" , "Xmas013" , "Xmas014" , "Xmas015" , "Xmas016" , "Xmas017" , "Xmas018" , "Xmas019" , "Xmas020" , "Xmas021" , "Xmas022" , "Xmas023" , "Xmas024" , "Xmas025" , "Xmas026" , "Xmas027" , "Xmas028" , "Xmas029" , "Xmas030" , "Xmas031" , "Xmas032" , "Xmas033" , "Xmas034" , "Xmas035" , "Xmas036" , "Xmas037" , "Xmas038" , "Xmas039" , "Xmas040" , "Xmas041" , "Xmas042" , "Xmas043" , "Xmas044" , "Xmas045" , "Xmas046" , "Xmas047" , "Xmas048" , "Xmas049" , "Xmas050" , "Xmas051" , "Xmas052" , "Xmas053" , "Xmas054" , "Xmas055" , "Xmas056" , "Xmas057" , "Xmas058" , "Xmas059" , "Xmas060" , "Xmas061" , "Xmas062" , "Xmas063" , "Xmas064" , "Xmas065" , "Xmas066" , "Xmas067" , "Xmas068" , "Xmas069" , "Xmas070" , "Xmas071" , "Xmas072" , "Xmas073" , "Xmas074" , "Xmas075" , "Xmas076" , "Xmas077"
};

so i was trying to do the follow, but that isnt work

void RUNMATRIX() {
  // Frame 1-77
  FastLED.clear();

  /////////////////////
  /*
  for (byte idx = 0; idx < sizeof(Xitems) / sizeof(Xitems[0]); idx++)
  {

    for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = pgm_read_dword(&(Xitems[idx][i]));
    }
  }
*/

////////////////  OR

for (int i = 0; i < NUM_LEDS; i++) {
  for (byte idx = 0; idx < sizeof(Xitems) / sizeof(Xitems[0]); idx++)
  {
        leds[i] = pgm_read_dword(&(Xitems[idx][i]));
}
}

any one that can help me?Processing: xmas301_T1.rar...
xmas301_T1.zip (7.1 KB)

Hello

When the program is compiled, variables doesn't have names, so you can't do what you are trying to do.

Instead, you can store pointers to these variables. See the example Arrays of strings (except yours aren't strings but arrays of longs, but the principle is the same)

Or, as your frames are all the same size, you can use a 2D array

Also you seem to be missing these lines from your for loop, so nothing will ever be displayed even when the pointers are correct.

You can't use names but you can use pointers (addresses).

uint32_t * Xitems[77] = {
  Xmas001 , Xmas002 , Xmas003 , Xmas004, Xmas005 ,
.
.
.
 Xmas073, Xmas074, Xmas075, Xmas076, Xmas077
};

You would then fetch the pixel with:
pgm_read_dword(&(Xitems[frame][i]));

Thx Johnwasser

I understand the principal.
but two questions

i got these error
cannot convert 'const char*' to 'uint32_t*'

and guess
pgm_read_dword(&(Xitems[frame][i]));

[frame] comes from
for (int i = 0; i < NUM_LEDS; i++) {
for (byte frame= 0; idx < sizeof(Xitems) / sizeof(Xitems[0]); frame++)
{
leds[i] = pgm_read_dword(&(Xitems[frame][i]));
}
}

i am very new to using arrays, so sorry for that :wink:

these is a project for my daughter xmas
i put the 32*8 matrix into a pull and so she will have a interactive pull for wxmass.
So thx to all for helping me.

How are your frames declared? I can only guess from the context how the parts you don't show are written. That is why it helps if you can provide your entire sketch. Less guessing so less guessing wrong.

It should be the other way around:

  for (byte frame = 0; frame < sizeof(Xitems) / sizeof(Xitems[0]); frame++)
  {
    for (int i = 0; i < NUM_LEDS; i++) 
    {
      leds[i] = pgm_read_dword(&(Xitems[frame][I]));
    }
  }

That way it does every pixel of each frame rather than one pixel of every frame for each pixel in turn.

many thanks

here my original code .ino

/* Arduino 256 RGB LEDs Matrix Animation Frame
   Using WS2812 LED Strips

  Created by Barre
*/

#include <avr/pgmspace.h>  // Needed to store stuff in Flash using PROGMEM
#include "FastLED.h"       // Fastled library to control the LEDs
#include "xmas.h"

// How many leds are connected?
#define NUM_LEDS 256

// Define the Data Pin
#define DATA_PIN RX  // Connected to the data pin of the first LED strip

// Define the trasistor pin
//#define R_PIN D2
int R_PIN = D2;

// Define the array of leds
CRGB leds[NUM_LEDS];

uint32_t * Xitems[77] = {
  "Xmas001" , "Xmas002" , "Xmas003" , "Xmas004" , "Xmas005" , "Xmas006" , "Xmas007" , "Xmas008" , "Xmas009" , "Xmas010" , "Xmas011" , "Xmas012" , "Xmas013" , "Xmas014" , "Xmas015" , "Xmas016" , "Xmas017" , "Xmas018" , "Xmas019" , "Xmas020" , "Xmas021" , "Xmas022" , "Xmas023" , "Xmas024" , "Xmas025" , "Xmas026" , "Xmas027" , "Xmas028" , "Xmas029" , "Xmas030" , "Xmas031" , "Xmas032" , "Xmas033" , "Xmas034" , "Xmas035" , "Xmas036" , "Xmas037" , "Xmas038" , "Xmas039" , "Xmas040" , "Xmas041" , "Xmas042" , "Xmas043" , "Xmas044" , "Xmas045" , "Xmas046" , "Xmas047" , "Xmas048" , "Xmas049" , "Xmas050" , "Xmas051" , "Xmas052" , "Xmas053" , "Xmas054" , "Xmas055" , "Xmas056" , "Xmas057" , "Xmas058" , "Xmas059" , "Xmas060" , "Xmas061" , "Xmas062" , "Xmas063" , "Xmas064" , "Xmas065" , "Xmas066" , "Xmas067" , "Xmas068" , "Xmas069" , "Xmas070" , "Xmas071" , "Xmas072" , "Xmas073" , "Xmas074" , "Xmas075" , "Xmas076" , "Xmas077"
};


void setup() {
  pinMode(R_PIN, OUTPUT);
  FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS); // Init of the Fastled library
  FastLED.setBrightness(50);
  FastLED.clear();
}

void loop() {
  //digitalWrite(R_PIN, HIGH); // turn transistor ON

    // LEDMATRIX();  /// long code
      RUNMATRIX();   // dynamical shorter code
}

void RUNMATRIX() {
  // Frame 1-77
  FastLED.clear();

  for (byte frame = 0; frame < sizeof(Xitems) / sizeof(Xitems[0]); frame++)
  {
    for (int i = 0; i < NUM_LEDS; i++) 
    {
      leds[i] = pgm_read_dword(&(Xitems[frame][I]));
    }
  }

    FastLED.show();
    delay(400);
 
}


void LEDMATRIX() {
  // Frame 1
  FastLED.clear();
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = pgm_read_dword(&(Xmas001[i]));
  }
  FastLED.show();
  delay(400);

  // Frame 2
  FastLED.clear();
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = pgm_read_dword(&(Xmas002[i]));
  }
  FastLED.show();
  delay(400);

  // Frame 3
  FastLED.clear();
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = pgm_read_dword(&(Xmas003[i]));
  }
  FastLED.show();
  delay(400);

  // Frame 4
  FastLED.clear();
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = pgm_read_dword(&(Xmas004[i]));
  }
  FastLED.show();
  delay(400);

  // Frame 5
  FastLED.clear();
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = pgm_read_dword(&(Xmas005[i]));
  }
  FastLED.show();
  delay(400);

  // Frame 6
  FastLED.clear();
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = pgm_read_dword(&(Xmas006[i]));
  }
  FastLED.show();
  delay(400);

  // Frame 7
  FastLED.clear();
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = pgm_read_dword(&(Xmas007[i]));
  }
  FastLED.show();
  delay(400);

  // Frame 8
  FastLED.clear();
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = pgm_read_dword(&(Xmas008[i]));
  }
  FastLED.show();
  delay(400);

  // Frame 9
  FastLED.clear();
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = pgm_read_dword(&(Xmas009[i]));
  }
  FastLED.show();
  delay(400);

  // Frame 10
  FastLED.clear();
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = pgm_read_dword(&(Xmas010[i]));
  }
  FastLED.show();
  delay(400);

  // Frame 11
  FastLED.clear();
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = pgm_read_dword(&(Xmas011[i]));
  }
  FastLED.show();
  delay(400);

  // Frame 12
  FastLED.clear();
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = pgm_read_dword(&(Xmas012[i]));
  }
  FastLED.show();
  delay(400);

  // Frame 13
  FastLED.clear();
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = pgm_read_dword(&(Xmas013[i]));
  }
  FastLED.show();
  delay(400);

  // Frame 14
  FastLED.clear();
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = pgm_read_dword(&(Xmas014[i]));
  }
  FastLED.show();
  delay(400);

  // Frame 15
  FastLED.clear();
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = pgm_read_dword(&(Xmas015[i]));
  }
  FastLED.show();
  delay(400);

  // Frame 16
  FastLED.clear();
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = pgm_read_dword(&(Xmas016[i]));
  }
  FastLED.show();
  delay(400);

  // Frame 17
  FastLED.clear();
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = pgm_read_dword(&(Xmas017[i]));
  }
  FastLED.show();
  delay(400);

  // Frame 18
  FastLED.clear();
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = pgm_read_dword(&(Xmas018[i]));
  }
  FastLED.show();
  delay(400);

  // Frame 19
  FastLED.clear();
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = pgm_read_dword(&(Xmas019[i]));
  }
  FastLED.show();
  delay(400);

  // Frame 20
  FastLED.clear();
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = pgm_read_dword(&(Xmas020[i]));
  }
  FastLED.show();
  delay(400);

  // Frame 21
  FastLED.clear();
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = pgm_read_dword(&(Xmas021[i]));
  }
  FastLED.show();
  delay(400);

  // Frame 22
  FastLED.clear();
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = pgm_read_dword(&(Xmas022[i]));
  }
  FastLED.show();
  delay(400);

  // Frame 23
  FastLED.clear();
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = pgm_read_dword(&(Xmas023[i]));
  }
  FastLED.show();
  delay(400);

  // Frame 24
  FastLED.clear();
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = pgm_read_dword(&(Xmas024[i]));
  }
  FastLED.show();
  delay(400);

  // Frame 25
  FastLED.clear();
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = pgm_read_dword(&(Xmas025[i]));
  }
  FastLED.show();
  delay(400);

  // Frame 26
  FastLED.clear();
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = pgm_read_dword(&(Xmas026[i]));
  }
  FastLED.show();
  delay(400);

  //
  // Frame 27
  FastLED.clear();
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = pgm_read_dword(&(Xmas027[i]));
  }
  FastLED.show();
  delay(400);

  // Frame 28
  FastLED.clear();
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = pgm_read_dword(&(Xmas028[i]));
  }
  FastLED.show();
  delay(400);

  // Frame 29
  FastLED.clear();
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = pgm_read_dword(&(Xmas029[i]));
  }
  FastLED.show();
  delay(400);

  // Frame 30
  FastLED.clear();
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = pgm_read_dword(&(Xmas030[i]));
  }
  FastLED.show();
  delay(400);

  // Frame 31
  FastLED.clear();
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = pgm_read_dword(&(Xmas031[i]));
  }
  FastLED.show();
  delay(400);

  // Frame 32
  FastLED.clear();
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = pgm_read_dword(&(Xmas032[i]));
  }
  FastLED.show();
  delay(400);

  // Frame 33
  FastLED.clear();
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = pgm_read_dword(&(Xmas033[i]));
  }
  FastLED.show();
  delay(400);

  // Frame 34
  FastLED.clear();
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = pgm_read_dword(&(Xmas034[i]));
  }
  FastLED.show();
  delay(400);

  // Frame 35
  FastLED.clear();
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = pgm_read_dword(&(Xmas035[i]));
  }
  FastLED.show();
  delay(400);

  // Frame 36
  FastLED.clear();
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = pgm_read_dword(&(Xmas036[i]));
  }
  FastLED.show();
  delay(400);

  // Frame 37
  FastLED.clear();
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = pgm_read_dword(&(Xmas037[i]));
  }
  FastLED.show();
  delay(400);

  // Frame 38
  FastLED.clear();
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = pgm_read_dword(&(Xmas038[i]));
  }
  FastLED.show();
  delay(400);

  // Frame 39
  FastLED.clear();
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = pgm_read_dword(&(Xmas039[i]));
  }
  FastLED.show();
  delay(400);

  // Frame 40
  FastLED.clear();
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = pgm_read_dword(&(Xmas040[i]));
  }
  FastLED.show();
  delay(400);

  // Frame 41
  FastLED.clear();
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = pgm_read_dword(&(Xmas041[i]));
  }
  FastLED.show();
  delay(400);

  // Frame 42
  FastLED.clear();
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = pgm_read_dword(&(Xmas042[i]));
  }
  FastLED.show();
  delay(400);

  // Frame 43
  FastLED.clear();
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = pgm_read_dword(&(Xmas043[i]));
  }
  FastLED.show();
  delay(400);

  // Frame 44
  FastLED.clear();
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = pgm_read_dword(&(Xmas044[i]));
  }
  FastLED.show();
  delay(400);

  // Frame 45
  FastLED.clear();
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = pgm_read_dword(&(Xmas045[i]));
  }
  FastLED.show();
  delay(400);

  // Frame 46
  FastLED.clear();
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = pgm_read_dword(&(Xmas046[i]));
  }
  FastLED.show();
  delay(400);

  // Frame 47
  FastLED.clear();
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = pgm_read_dword(&(Xmas047[i]));
  }
  FastLED.show();
  delay(400);

  // Frame 48
  FastLED.clear();
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = pgm_read_dword(&(Xmas048[i]));
  }
  FastLED.show();
  delay(400);

  // Frame 49
  FastLED.clear();
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = pgm_read_dword(&(Xmas049[i]));
  }
  FastLED.show();
  delay(400);

  // Frame 50
  FastLED.clear();
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = pgm_read_dword(&(Xmas050[i]));
  }
  FastLED.show();
  delay(400);

  // Frame 51
  FastLED.clear();
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = pgm_read_dword(&(Xmas051[i]));
  }
  FastLED.show();
  delay(400);

  // Frame 52
  FastLED.clear();
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = pgm_read_dword(&(Xmas052[i]));
  }
  FastLED.show();
  delay(400);

  // Frame 53
  FastLED.clear();
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = pgm_read_dword(&(Xmas053[i]));
  }
  FastLED.show();
  delay(400);

  // Frame 54
  FastLED.clear();
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = pgm_read_dword(&(Xmas054[i]));
  }
  FastLED.show();
  delay(400);

  // Frame 55
  FastLED.clear();
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = pgm_read_dword(&(Xmas055[i]));
  }
  FastLED.show();
  delay(400);

  // Frame 56
  FastLED.clear();
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = pgm_read_dword(&(Xmas056[i]));
  }
  FastLED.show();
  delay(400);

  // Frame 57
  FastLED.clear();
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = pgm_read_dword(&(Xmas057[i]));
  }
  FastLED.show();
  delay(400);

  // Frame 58
  FastLED.clear();
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = pgm_read_dword(&(Xmas058[i]));
  }
  FastLED.show();
  delay(400);

  // Frame 59
  FastLED.clear();
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = pgm_read_dword(&(Xmas059[i]));
  }
  FastLED.show();
  delay(400);

  // Frame 60
  FastLED.clear();
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = pgm_read_dword(&(Xmas060[i]));
  }
  FastLED.show();
  delay(400);

  // Frame 61
  FastLED.clear();
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = pgm_read_dword(&(Xmas061[i]));
  }
  FastLED.show();
  delay(400);

  // Frame 62
  FastLED.clear();
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = pgm_read_dword(&(Xmas062[i]));
  }
  FastLED.show();
  delay(400);

  // Frame 63
  FastLED.clear();
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = pgm_read_dword(&(Xmas063[i]));
  }
  FastLED.show();
  delay(400);

  // Frame 64
  FastLED.clear();
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = pgm_read_dword(&(Xmas064[i]));
  }
  FastLED.show();
  delay(400);

  // Frame 65
  FastLED.clear();
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = pgm_read_dword(&(Xmas065[i]));
  }
  FastLED.show();
  delay(400);

  // Frame 66
  FastLED.clear();
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = pgm_read_dword(&(Xmas066[i]));
  }
  FastLED.show();
  delay(400);

  // Frame 67
  FastLED.clear();
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = pgm_read_dword(&(Xmas067[i]));
  }
  FastLED.show();
  delay(400);

  // Frame 68
  FastLED.clear();
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = pgm_read_dword(&(Xmas068[i]));
  }
  FastLED.show();
  delay(400);

  // Frame 69
  FastLED.clear();
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = pgm_read_dword(&(Xmas069[i]));
  }
  FastLED.show();
  delay(400);

  // Frame 70
  FastLED.clear();
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = pgm_read_dword(&(Xmas070[i]));
  }
  FastLED.show();
  delay(400);

  // Frame 71
  FastLED.clear();
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = pgm_read_dword(&(Xmas071[i]));
  }
  FastLED.show();
  delay(400);

  // Frame 72
  FastLED.clear();
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = pgm_read_dword(&(Xmas072[i]));
  }
  FastLED.show();
  delay(400);

  // Frame 73
  FastLED.clear();
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = pgm_read_dword(&(Xmas073[i]));
  }
  FastLED.show();
  delay(400);

  // Frame 74
  FastLED.clear();
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = pgm_read_dword(&(Xmas074[i]));
  }
  FastLED.show();
  delay(400);

  // Frame 75
  FastLED.clear();
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = pgm_read_dword(&(Xmas075[i]));
  }
  FastLED.show();
  delay(400);

  // Frame 76
  FastLED.clear();
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = pgm_read_dword(&(Xmas076[i]));
  }
  FastLED.show();
  delay(400);

  // Frame 77
  FastLED.clear();
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = pgm_read_dword(&(Xmas077[i]));
  }
  FastLED.show();
  delay(400);

}

above i got the error
cannot convert 'const char*' to 'uint32_t*' {aka 'unsigned int*'} in initialization

full code in start as attachament

I don't see the contents of 'xmas.h'. How are your frames declared?

OK. I think I have it fixed.

Your data is too big to fit into 64kB so you can't use the usual 16-bit pointers and array indexing. It took a while but I finally found that casting the frames to 'uint_farptr_t' (a.k.a. 'uint32_t') I could store the PROGMEM address in an array. Then, using "pgm_read_dword**_far**" you can fetch each pixel as a dword from a calculated PROGMEM address.

It compiles fine for an Arduino Mega 2560.

/* Arduino 256 RGB LEDs Matrix Animation Frame
   Using WS2812 LED Strips

  Created by Barre
*/

#include <avr/pgmspace.h>  // Needed to store stuff in Flash using PROGMEM
#include "FastLED.h"       // Fastled library to control the LEDs
#include "xmas.h"

// How many leds are connected?
#define NUM_LEDS 256

// Define the Data Pin
const byte DATA_PIN = RX;  // Connected to the data pin of the first LED strip

// Define the trasistor pin
const byte R_PIN = D2;

// Define the array of leds
CRGB leds[NUM_LEDS];

const uint_farptr_t Xitems[77] =
{
  (uint_farptr_t)Xmas001, (uint_farptr_t)Xmas002, (uint_farptr_t)Xmas003, 
  (uint_farptr_t)Xmas004, (uint_farptr_t)Xmas005, (uint_farptr_t)Xmas006, 
  (uint_farptr_t)Xmas007, (uint_farptr_t)Xmas008, (uint_farptr_t)Xmas009, 
  (uint_farptr_t)Xmas010, (uint_farptr_t)Xmas011, (uint_farptr_t)Xmas012, 
  (uint_farptr_t)Xmas013, (uint_farptr_t)Xmas014, (uint_farptr_t)Xmas015, 
  (uint_farptr_t)Xmas016, (uint_farptr_t)Xmas017, (uint_farptr_t)Xmas018, 
  (uint_farptr_t)Xmas019, (uint_farptr_t)Xmas020, (uint_farptr_t)Xmas021, 
  (uint_farptr_t)Xmas022, (uint_farptr_t)Xmas023, (uint_farptr_t)Xmas024, 
  (uint_farptr_t)Xmas025, (uint_farptr_t)Xmas026, (uint_farptr_t)Xmas027, 
  (uint_farptr_t)Xmas028, (uint_farptr_t)Xmas029, (uint_farptr_t)Xmas030, 
  (uint_farptr_t)Xmas031, (uint_farptr_t)Xmas032, (uint_farptr_t)Xmas033, 
  (uint_farptr_t)Xmas034, (uint_farptr_t)Xmas035, (uint_farptr_t)Xmas036, 
  (uint_farptr_t)Xmas037, (uint_farptr_t)Xmas038, (uint_farptr_t)Xmas039, 
  (uint_farptr_t)Xmas040, (uint_farptr_t)Xmas041, (uint_farptr_t)Xmas042, 
  (uint_farptr_t)Xmas043, (uint_farptr_t)Xmas044, (uint_farptr_t)Xmas045, 
  (uint_farptr_t)Xmas046, (uint_farptr_t)Xmas047, (uint_farptr_t)Xmas048, 
  (uint_farptr_t)Xmas049, (uint_farptr_t)Xmas050, (uint_farptr_t)Xmas051, 
  (uint_farptr_t)Xmas052, (uint_farptr_t)Xmas053, (uint_farptr_t)Xmas054, 
  (uint_farptr_t)Xmas055, (uint_farptr_t)Xmas056, (uint_farptr_t)Xmas057, 
  (uint_farptr_t)Xmas058, (uint_farptr_t)Xmas059, (uint_farptr_t)Xmas060, 
  (uint_farptr_t)Xmas061, (uint_farptr_t)Xmas062, (uint_farptr_t)Xmas063, 
  (uint_farptr_t)Xmas064, (uint_farptr_t)Xmas065, (uint_farptr_t)Xmas066, 
  (uint_farptr_t)Xmas067, (uint_farptr_t)Xmas068, (uint_farptr_t)Xmas069, 
  (uint_farptr_t)Xmas070, (uint_farptr_t)Xmas071, (uint_farptr_t)Xmas072, 
  (uint_farptr_t)Xmas073, (uint_farptr_t)Xmas074, (uint_farptr_t)Xmas075, 
  (uint_farptr_t)Xmas076, (uint_farptr_t)Xmas077
};

void setup()
{
  pinMode(R_PIN, OUTPUT);
  FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS); // Init of the Fastled library
  FastLED.setBrightness(50);
  FastLED.clear();
}

void loop()
{
  //digitalWrite(R_PIN, HIGH); // turn transistor ON

  // LEDMATRIX();
  RUNMATRIX();
}

void RUNMATRIX()
{
  // Frame 1-77
  FastLED.clear();

  for (byte frame = 0; frame < sizeof(Xitems) / sizeof(Xitems[0]); frame++)
  {
    uint_farptr_t ptr = Xitems[frame];
    
    for (long i = 0; i < NUM_LEDS; i++)
    {
      // Each pixel is a 'long' (a.k.a. 'dword')
      leds[i] = pgm_read_dword_far (ptr + (i * sizeof (long)));
    }
    
    FastLED.show();
    delay(400);
  }
}
1 Like

You can reduce memory usage by more than 2/3 if you didn't store pixels with a value 0 and use the first (unused) byte of the other values as the pixel index (it will work because you have only 256 LEDs)

Here is an example for the first few frames : fastled_progmem_xmas.ino - Wokwi Arduino and ESP32 Simulator

Adding more frames is as simple as copy/pasting your arrays and enable the array generator... :slight_smile:

And to reduce memory even more, as you don't use much colors (white, red and a few others), maybe you could store these colors separately in another array, and the frames pixels would store a one byte index to these colors...

1 Like

Thanks all
realy al helpfull.

I think i have a problem that my D1 mini is not complient with the codes
(sorry for the late posting of the type development board)
i get the error

'uint_farptr_t' does not name a type; did you mean 'uint_fast8_t'?

I figured something was odd when you used the pin 'D2' instead of '2'. For a D1 you probably don't need PROGMEM at all since program memory and RAM are in the same address space.

/* Arduino 256 RGB LEDs Matrix Animation Frame
   Using WS2812 LED Strips

  Created by Barre
*/

#include "FastLED.h"       // Fastled library to control the LEDs
#include "xmas.h"

// How many leds are connected?
#define NUM_LEDS 256

// Define the Data Pin
const byte DATA_PIN = RX;  // Connected to the data pin of the first LED strip

// Define the transistor pin
const byte R_PIN = D2;

// Define the array of leds
CRGB leds[NUM_LEDS];

const long int * Xitems[77] =
{
  Xmas001, Xmas002, Xmas003, 
  Xmas004, Xmas005, Xmas006, 
  Xmas007, Xmas008, Xmas009, 
  Xmas010, Xmas011, Xmas012, 
  Xmas013, Xmas014, Xmas015, 
  Xmas016, Xmas017, Xmas018, 
  Xmas019, Xmas020, Xmas021, 
  Xmas022, Xmas023, Xmas024, 
  Xmas025, Xmas026, Xmas027, 
  Xmas028, Xmas029, Xmas030, 
  Xmas031, Xmas032, Xmas033, 
  Xmas034, Xmas035, Xmas036, 
  Xmas037, Xmas038, Xmas039, 
  Xmas040, Xmas041, Xmas042, 
  Xmas043, Xmas044, Xmas045, 
  Xmas046, Xmas047, Xmas048, 
  Xmas049, Xmas050, Xmas051, 
  Xmas052, Xmas053, Xmas054, 
  Xmas055, Xmas056, Xmas057, 
  Xmas058, Xmas059, Xmas060, 
  Xmas061, Xmas062, Xmas063, 
  Xmas064, Xmas065, Xmas066, 
  Xmas067, Xmas068, Xmas069, 
  Xmas070, Xmas071, Xmas072, 
  Xmas073, Xmas074, Xmas075, 
  Xmas076, Xmas077
};

void setup()
{
  pinMode(R_PIN, OUTPUT);
  FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS); // Init of the Fastled library
  FastLED.setBrightness(50);
  FastLED.clear();
}

void loop()
{
  //digitalWrite(R_PIN, HIGH); // turn transistor ON

  // LEDMATRIX();
  RUNMATRIX();
}

void RUNMATRIX()
{
  // Frame 1-77
  FastLED.clear();

  for (byte frame = 0; frame < sizeof(Xitems) / sizeof(Xitems[0]); frame++)
  {
    const long int * ptr = Xitems[frame];
    
    for (long i = 0; i < NUM_LEDS; i++)
    {
      // Each pixel is a 'long' (a.k.a. 'dword')
      leds[i] = ptr[i];
    }
    
    FastLED.show();
    delay(400);
  }
}
1 Like

After a closer look, all your frames are using a total of 8 colors, so one pixel color can be stored with only 3 bits, one frame would use 96 bytes instead of 1kB originally... :wink:

Or, easier, store the color with 4 bits (so you can have 16 colors if needed), and one frame will take 128 bytes

Here is a demo with 4 bits colors : fastled_xmas_demo.ino - Wokwi Arduino and ESP32 Simulator

It was not possible to convert all your arrays at once because they were too big even for an Arduino Mega (at least with Wokwi simulator), so I used an ESP32 for generating the arrays : fastled_xmas_gen.ino - Wokwi Arduino and ESP32 Simulator

1 Like

johnwasser and guix your are angels

many thanks for your helps.

i will post both solutionsxmas.h (235.9 KB)
xmas_4.0.1.ino (1.7 KB)

Hello everyone.

I threw everything on GitHub.
This is a project in WIP.

Thanks for all the tips.

https://github.com/users/barremans/projects/1

Still a few steps to go, but it's already working.
Video will be posted later.

Greetings Barre

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.