[HELP] Read hex value from array problem

I cannot manage to read the value from a hex array of the type: {0x000000,0xf8dc00,0xf8dc00,0xf8db00,0xf7db00,0xf8db00,0x000000}.
Basically they're a series of colour values in the format FFFFFF.
I tried to declare the array as static uint32_t hello_01_data[] PROGMEM= {...} and read it as hello_01_data[index].

Any help?


You can't read back data declared in the PROGMEM section like that. See PROGMEM - Arduino Reference

Umh… can you give me an example of how I can declare an array of colour values in hex format and read it at run time ? Can I declare the array as a simple static array (= no PROGMEM) in a .h file and include the object as usual (the array should contain 1024 HEX values)?

I have an RGB matrix display and wrote a drawPixel(x,y, color) kind of function… now I would like to display colour values (= pixels) based on an array (= image). In practice:

//pixels[] is a one dimensional static array of length w*h. The values are like 0xFF3A00, 0xAABB00, 0x000000, 0x00FFFF, ...
void drawImage(const uint32_t *pixels, int16_t w, int16_t h) {
  int x, y;
  for(y=0; y<h; y++) {
    for(x=0; x<w; x++ ) {
      if(pixels[x+y*w] > 0x000000)         // if the pixel value is not black then draw it
          drawPixel(x, y, pixels[x+y*w]);  // pixels[x+y*w] should return a value in the format 0xFFFFFF

There are functions provided in pgmspace.h which allow you to read different sizes of data.

uint32_t ReadData = pgm_read_dword(&hello_01_data[ index ] );


Is uint32_t the right type for a hex value like 0xFFaabb ? When I read pgm_read_dword(pixels*) it doesn't return a hex value...*

That hex value is 32 bits large, so yes, uint32_t is the correct type.

I imagine it is returning a "hex" value, in the sense that hexadecimal is just a way of representing a number and so if it returns a value then that value can be represented in hex. What value do you get when you call that method? And could you post your code so we can see how you're calling it?

A number is a number is a number.

You can have a number in an array element and you can display it as a hex or decimal or octal or any other display format that you want.