pgm_read and buffer

ok so here i have a 49x18 led array, "CASE A" pulls back the correct data and display the correct pattern and colours (not using a buffer), however "CASE B" (using a buffer) pulls back the correct pattern but not the correct colours

Question is do i really need a buffer?, what is its purpose if CASE A runs with out it?

Question 2 if i do need a buffer, what is wrong with mine?

i have limited coding knowledge im just learning as i go

Thanks

#include <Adafruit_NeoPixel.h>

#define PIN 6
#define NUM_LEDS 882

#include "new.h"

Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ800);
word buffer{900};

void setup()
{
    strip.begin();
    strip.setBrightness(10);
    strip.show();   // Initialize all pixels to 'off'
    Serial.begin(9600); // keyboard input
}

void loop() {
  // read the sensor:
  if (Serial.available() > 0) {
    int inByte = Serial.read();
    switch (inByte) {


    case 'a':
    for (int t = 0; t < NUM_LEDS; t++)
    {
    strip.setPixelColor(t,pgm_read_dword(&(ledarray222[t])) );
    }
     strip.show(); 
    break;


    case 'b':
    for (int t = 0; t < NUM_LEDS; t++)
    {
    buffer = (pgm_read_dword(&(ledarray222[t])));
    strip.setPixelColor(t, buffer);
    }
     strip.show(); 
   break;

  }
  }
}
const PROGMEM uint32_t ledarray222[] = {
                       0x000088FF, 0x000088FF, 0x000088FF, 0x000088FF, 0x0000FF00, 0x0000FF00, 0x0000FF00, 0x0000FF00, 0x0000FF00, 0x0000FF00, 0x0000FF00, 0x0000FF00, 0x0000FF00, 0x0000FF00, 0x0000FF00, 0x0000FF00, 0x0000FF00, 0x0000FF00, 0x0000FF00, 0x0000FF00, 0x0000FF00, 0x0000FF00, 0x0000FF00, 0x0000FF00, 0x0000FF00, 0x0000FF00, 0x0000FF00, 0x0000FF00, 0x0000FF00, 0x0000FF00, 0x0000FF00, 0x0000FF00, 0x0000FF00, 0x0000FF00, 0x0000FF00, 0x0000FF00, 0x0000FF00, 0x0000FF00, 0x0000FF00, 0x0000FF00, 0x0000FF00, 0x0000FF00, 0x0000FF00, 0x0000FF00, 0x000088FF, 0x000088FF, 0x000088FF, 0x000088FF, 0x0000FF00, 
                       0x0000FF00, 0x000088FF, 0x000088FF, 0x000088FF, 0x000088FF, 0x0000FF00, 0x000088FF, 0x000088FF, 0x00FF00FF, 0x00FF00FF, 0x000088FF, 0x000088FF, 0x0000FF00, 0x0000FF00, 0x000088FF, 0x000088FF, 0x00FF00FF, 0x00FF00FF, 0x000088FF, 0x000088FF, 0x0000FF00, 0x0000FF00, 0x000088FF, 0x000088FF, 0x00FF00FF, 0x00FF00FF, 0x000088FF, 0x000088FF, 0x0000FF00, 0x0000FF00, 0x000088FF, 0x000088FF, 0x00FF00FF, 0x00FF00FF, 0x000088FF, 0x000088FF, 0x0000FF00, 0x0000FF00, 0x000088FF, 0x000088FF, 0x00FF00FF, 0x00FF00FF, 0x000088FF, 0x000088FF, 0x0000FF00, 0x000088FF, 0x000088FF, 0x000088FF, 0x000088FF, 
                       0x000088FF, 0x000088FF, 0x000088FF, 0x000088FF, 0x0000FF00, 0x000088FF, 0x000088FF, 0x00FF00FF, 0x00FF00FF, 0x000088FF, 0x000088FF, 0x0000FF00, 0x0000FF00, 0x000088FF, 0x000088FF, 0x00FF00FF, 0x00FF00FF, 0x000088FF, 0x000088FF, 0x0000FF00, 0x0000FF00, 0x000088FF, 0x000088FF, 0x00FF00FF, 0x00FF00FF, 0x000088FF, 0x000088FF, 0x0000FF00, 0x0000FF00, 0x000088FF, 0x000088FF, 0x00FF00FF, 0x00FF00FF, 0x000088FF, 0x000088FF, 0x0000FF00, 0x0000FF00, 0x000088FF, 0x000088FF, 0x00FF00FF, 0x00FF00FF, 0x000088FF, 0x000088FF, 0x0000FF00, 0x000088FF, 0x000088FF, 0x000088FF, 0x000088FF, 0x0000FF00, 
                       0x0000FF00, 0x0000FF00, 0x00FF00FF, 0x00FF00FF, 0x0000FF00, 0x0000FF00, 0x00FF00FF, 0x00FF00FF, 0x0000FF00, 0x0000FF00, 0x00FF00FF, 0x00FF00FF, 0x0000FF00, 0x0000FF00, 0x00FF00FF, 0x00FF00FF, 0x0000FF00, 0x0000FF00, 0x00FF00FF, 0x00FF00FF, 0x0000FF00, 0x0000FF00, 0x00FF00FF, 0x00FF00FF, 0x0000FF00, 0x0000FF00, 0x00FF00FF, 0x00FF00FF, 0x0000FF00, 0x0000FF00, 0x00FF00FF, 0x00FF00FF, 0x0000FF00, 0x0000FF00, 0x00FF00FF, 0x00FF00FF, 0x0000FF00, 0x0000FF00, 0x00FF00FF, 0x00FF00FF, 0x0000FF00, 0x0000FF00, 0x00FF00FF, 0x00FF00FF, 0x0000FF00, 0x0000FF00, 0x00FF00FF, 0x00FF00FF, 0x0000FF00, 
                       0x0000FF00, 0x00FF00FF, 0x00FF00FF, 0x0000FF00, 0x0000FF00, 0x00FF00FF, 0x00FF00FF, 0x0000FF00, 0x0000FF00, 0x00FF00FF, 0x00FF00FF, 0x0000FF00, 0x0000FF00, 0x00FF00FF, 0x00FF00FF, 0x0000FF00, 0x0000FF00, 0x00FF00FF, 0x00FF00FF, 0x0000FF00, 0x0000FF00, 0x00FF00FF, 0x00FF00FF, 0x0000FF00, 0x0000FF00, 0x00FF00FF, 0x00FF00FF, 0x0000FF00, 0x0000FF00, 0x00FF00FF, 0x00FF00FF, 0x0000FF00, 0x0000FF00, 0x00FF00FF, 0x00FF00FF, 0x0000FF00, 0x0000FF00, 0x00FF00FF, 0x00FF00FF, 0x0000FF00, 0x0000FF00, 0x00FF00FF, 0x00FF00FF, 0x0000FF00, 0x0000FF00, 0x00FF00FF, 0x00FF00FF, 0x0000FF00, 0x0000FF00, 
                       0x0000FF00, 0x0000FF00, 0x000088FF, 0x000088FF, 0x0000FF00, 0x0000FF00, 0x000088FF, 0x000088FF, 0x0000FF00, 0x0000FF00, 0x000088FF, 0x000088FF, 0x0000FF00, 0x0000FF00, 0x000088FF, 0x000088FF, 0x0000FF00, 0x0000FF00, 0x000088FF, 0x000088FF, 0x0000FF00, 0x0000FF00, 0x000088FF, 0x000088FF, 0x0000FF00, 0x0000FF00, 0x000088FF, 0x000088FF, 0x0000FF00, 0x0000FF00, 0x000088FF, 0x000088FF, 0x0000FF00, 0x0000FF00, 0x000088FF, 0x000088FF, 0x0000FF00, 0x0000FF00, 0x000088FF, 0x000088FF, 0x0000FF00, 0x0000FF00, 0x000088FF, 0x000088FF, 0x0000FF00, 0x0000FF00, 0x000088FF, 0x000088FF, 0x0000FF00, 

                       };

This line

          buffer = (pgm_read_dword(&(ledarray222[t])));

returns one 32bit integer. You have declared buffer as an array of size 'word'

You should have declared buffer as a uint32_t

This looks like nonsense:

word buffer{900};

What is 'buffer'? Not an array. Perhaps a word variable initialized to 900?

excellent thank you that's been baffling me something so simple

if i was to add "CASE C" but to optimise the array code like this

const PROGMEM uint32_t leddataindex2[] = {
0x000000FF, 0x0000FF00, 0x0000FF40, 0x008000FF, 0x00FF0000};

const PROGMEM uint8_t ledarray2[] = {
                       1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
                       1, 1, 0, 0, 4, 4, 0, 0, 4, 4, 0, 0, 4, 4, 1, 2, 4, 4, 0, 0, 4, 4, 0, 0, 4, 4, 1, 1, 4, 4, 0, 0, 4, 4, 0, 0, 4, 4, 0, 0, 1, 1, 0, 0, 4, 4, 3, 3, 3, 
                       3, 3, 3, 4, 4, 0, 0, 1, 1, 0, 0, 4, 4, 0, 0, 4, 4, 0, 0, 4, 4, 1, 1, 4, 4, 0, 0, 4, 4, 0, 0, 4, 4, 2, 1, 4, 4, 0, 0, 4, 4, 0, 0, 4, 4, 0, 0, 1, 1, 
                       1, 1, 4, 4, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 4, 4, 1, 1, 4, 4, 1, 1, 1, 1, 1, 
                       1, 1, 1, 1, 1, 4, 4, 1, 1, 4, 4, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 4, 4, 1, 1, 
                       1, 1, 0, 0, 1, 1, 1, 1, 4, 4, 0, 0, 4, 4, 1, 1, 4, 4, 0, 0, 4, 4, 1, 1, 4, 4, 1, 1, 4, 4, 0, 0, 1, 1, 0, 0, 4, 4, 0, 0, 1, 1, 0, 0, 4, 4, 0, 0, 1, 
                       1, 0, 0, 4, 4, 0, 0, 1, 1, 0, 0, 4, 4, 0, 0, 1, 1, 0, 0, 4, 4, 1, 1, 4, 4, 1, 1, 4, 4, 0, 0, 4, 4, 1, 1, 4, 4, 0, 0, 4, 4, 1, 1, 1, 1, 0, 0, 1, 1, 
                       1, 1, 4, 4, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 4, 4, 1, 1, 4, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 4, 4, 1, 
                       1, 4, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 4, 4, 1, 1, 4, 4, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 2, 2, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 4, 4, 1, 1, 
                       1, 1, 1, 1, 4, 4, 1, 1, 4, 4, 1, 1, 4, 4, 0, 0, 4, 4, 1, 1, 4, 4, 1, 1, 4, 4, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 4, 4, 0, 0, 1, 1, 0, 0, 1, 
                       1, 0, 0, 1, 1, 0, 0, 4, 4, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 4, 4, 1, 1, 4, 4, 1, 1, 4, 4, 0, 0, 4, 4, 1, 1, 4, 4, 1, 1, 4, 4, 1, 1, 1, 1, 
                       1, 1, 4, 4, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 4, 4, 1, 1, 4, 4, 1, 1, 4, 4, 1, 1, 4, 4, 1, 1, 4, 4, 1, 1, 4, 4, 1, 
                       1, 4, 4, 1, 1, 4, 4, 1, 1, 4, 4, 1, 1, 4, 4, 1, 1, 4, 4, 1, 1, 4, 4, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 4, 4, 1, 1, 
                       1, 1, 0, 0, 1, 1, 1, 1, 4, 4, 1, 1, 4, 4, 1, 1, 4, 4, 1, 1, 4, 4, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 
                       1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 4, 4, 1, 1, 4, 4, 1, 1, 4, 4, 1, 1, 4, 4, 1, 1, 1, 1, 0, 0, 1, 1, 
                       3, 3, 4, 4, 1, 1, 1, 1, 0, 0, 4, 4, 0, 0, 1, 1, 0, 0, 4, 4, 0, 0, 1, 1, 1, 1, 4, 4, 0, 0, 4, 4, 1, 1, 4, 4, 0, 0, 4, 4, 1, 1, 4, 4, 0, 0, 4, 4, 1, 
                       1, 4, 4, 0, 0, 4, 4, 1, 1, 4, 4, 0, 0, 4, 4, 1, 1, 4, 4, 0, 0, 4, 4, 1, 1, 1, 1, 0, 0, 4, 4, 0, 0, 1, 1, 0, 0, 4, 4, 0, 0, 1, 1, 1, 1, 4, 4, 3, 3, 
                       1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
                       };

the normal code to pull that up would be 'leddataindex2[ledarray2[t]]' which works if the array isn't in the PROGMEM

but put it in the PROGMEM and my code doesn't pull up the correct display, is that easily do able or will i have to add in a second for loop?

   case 'c':
    for (int t = 0; t < NUM_LEDS; t++)
    {
    buffer = (pgm_read_dword(&(leddataindex2[ledarray2[t]])));
    strip.setPixelColor(t, buffer);
    }
     strip.show(); 
   break;

gfvalvo:
This looks like nonsense:

word buffer{900};

What is 'buffer'? Not an array. Perhaps a word variable initialized to 900?

i have changed that to uint32_t as suggested by blh64 which now works

This is the part that doesn't make sense to me:
word buffer**{900}**;
It compiles. But what do you think it does?

i just picked a high number when i was originally try to debug my first question myself, i based this off how many leds i had and how many items was in my array

my understanding now is this is the amount of bytes set a side, correct?

w4ynz:
my understanding now is this is the amount of bytes set a side, correct?

Nope. Arrays are defined with square brackets:

uint32_t buffer[10];

And, the number in the brackets in the number of elements, not bytes.

So, I don't know what your notation with the curl brackets {} does, and apparently neither do you. Where did you find that notation?

word buffer{900};

is equivalent to

word buffer = 900;

https://en.cppreference.com/w/cpp/language/list_initialization

oqibidipo:

word buffer{900};

is equivalent to

word buffer = 900;

List-initialization (since C++11) - cppreference.com

Thanks. That was my guess back in Reply #2.