Convert multi-dimensional arrays for use with ESP32 Dev Kit

In my current project, I have several multi-dimensional arrays (usually stored in a .h file) that a user can select from. Upon being selected, the code increments through each point in the array. if there is a zero, its left blank. if there is anything else, it draws on that pixel.

I have gotten the code as it currently is to run properly on an atmega328p, so I know that it conceptually works. this is the error I am getting try to migrate to the ESP32 Dev Kit.

invalid conversion from 'uint16_t {aka short unsigned int}' to 'const byte ()[8] {aka const unsigned char ()[8]}' [-fpermissive]

I've been playing with this for a few hours, but I just cant figure it out. This is the necessary minimum parts of the code to recreate the error. any assistance with figuring this out would be appreciated

#include <FastLED.h>
#include <FastLED_NeoMatrix.h>
#include <Adafruit_GFX.h>
uint16_t taskList[]= {pic1, pic , pic3};
byte set=0;
byte counter=1;

int x = matrix->width();
FastLED_NeoMatrix *matrix = new FastLED_NeoMatrix(256, 32, 8,
                            NEO_MATRIX_BOTTOM     + NEO_MATRIX_RIGHT +
                            NEO_MATRIX_COLUMNS + NEO_MATRIX_ZIGZAG);

void loop() {
  // put your main code here, to run repeatedly:
      if (set>2) set=0;
      bar(taskList[set]);
      break;
}

void bar(const byte z[8][8])
{ matrix->fillScreen(0);
  for (int i = 0; i < 256; i++) {
    //clear screen
    matrix->fillScreen(0);
    for (int row = 0; row < 8; row++) {
      for (int column = 0; column < 8; column++) {
        if (pgm_read_byte(&(z[row][column])) == 1)
        {
          //draw new picture
          matrix->drawPixel(column + x, row, matrix->Color(255, 0, 0));
        }
      }
    }
    //send picture to start of Matrix if picture has reached the end
    if (--x < -8)x = 32;
    matrix->show();
    delay(30);
  }
}



const byte pic1[8][8] PROGMEM= {  
   {0, 0, 0, 0, 0, 0, 0, 0},
   {0, 0, 0, 0, 0, 0, 0, 0},
   {0, 0, 0, 0, 0, 0, 0, 0},
   {0, 0, 0, 0, 0, 0, 0, 0},
   {0, 0, 0, 0, 0, 0, 0, 0},
   {0, 0, 0, 0, 0, 0, 0, 0},
   {0, 0, 0, 0, 0, 0, 0, 0},
   {0, 0, 0, 0, 0, 0, 0, 0}
  };
const byte pic2[8][8] PROGMEM= {  
   {1, 0, 0, 0, 0, 0, 0, 0},
   {0, 1, 0, 0, 0, 0, 0, 0},
   {0, 0, 1, 0, 0, 0, 0, 0},
   {0, 0, 0, 1, 0, 0, 0, 0},
   {0, 0, 0, 0, 1, 0, 0, 0},
   {0, 0, 0, 0, 0, 1, 0, 0},
   {0, 0, 0, 0, 0, 0, 1, 0},
   {0, 0, 0, 0, 0, 0, 0, 1}
  };
  const byte pic3[8][8] PROGMEM= {  
   {1, 0, 0, 0, 0, 0, 0, 1},
   {0, 1, 0, 0, 0, 0, 1, 0},
   {0, 0, 1, 0, 0, 1, 0, 0},
   {0, 0, 0, 1, 1, 0, 0, 0},
   {0, 0, 0, 1, 1, 0, 0, 0},
   {0, 0, 1, 0, 0, 1, 0, 0},
   {0, 1, 0, 0, 0, 0, 1, 0},
   {1, 0, 0, 0, 0, 0, 0, 1}
  };

What line gives this error? You cannot store a variable into a constant.

This is the necessary minimum parts of the code to recreate the error

Not really. The code provided does not compile without other errors than the array declaration.

//uint16_t taskList[]= {pic1, pic , pic3};
byte taskList[3][8][8] = {};

the error comes at this line

      bar(taskList[set]);

tasklist is not a const byte 8x8 array. It could point to some, though.

Are you suggesting declaring taskList as a 3-d array and then assigning a pointer to it?

Pointers in C/C++ are among the more awful of all possible inventions, ever.

One possible approach:


const byte pic1[8][8] = {
  {3, 0, 0, 0, 0, 0, 0, 0},
  {0, 0, 0, 0, 0, 0, 0, 0},
  {0, 0, 0, 0, 0, 0, 0, 0},
  {0, 0, 0, 0, 0, 0, 0, 0},
  {0, 0, 0, 0, 0, 0, 0, 0},
  {0, 0, 0, 0, 0, 0, 0, 0},
  {0, 0, 0, 0, 0, 0, 0, 0},
  {0, 0, 0, 0, 0, 0, 0, 0}
};
const byte pic2[8][8] = {
  {1, 0, 0, 0, 0, 0, 0, 0},
  {0, 1, 0, 0, 0, 0, 0, 0},
  {0, 0, 1, 0, 0, 0, 0, 0},
  {0, 0, 0, 1, 0, 0, 0, 0},
  {0, 0, 0, 0, 1, 0, 0, 0},
  {0, 0, 0, 0, 0, 1, 0, 0},
  {0, 0, 0, 0, 0, 0, 1, 0},
  {0, 0, 0, 0, 0, 0, 0, 1}
};
const byte pic3[8][8] = {
  {0, 0, 0, 0, 0, 0, 0, 1},
  {0, 1, 0, 0, 0, 0, 1, 0},
  {0, 0, 1, 0, 0, 1, 0, 0},
  {0, 0, 0, 1, 1, 0, 0, 0},
  {0, 0, 0, 1, 1, 0, 0, 0},
  {0, 0, 1, 0, 0, 1, 0, 0},
  {0, 1, 0, 0, 0, 0, 1, 0},
  {1, 0, 0, 0, 0, 0, 0, 1}
};

const byte (*taskList[])[8] = {pic1, pic2, pic3};

void print00(const byte z[][8]) {
  Serial.print("z00: ");
  Serial.println(z[0][0]);
}

void setup() {
  Serial.begin(115200);
  Serial.println("test");
  print00(taskList[0]);
  print00(taskList[1]);
  print00(taskList[2]);
}
void loop() {
}
1 Like

Thank you, I about cried after trying to understand pointers for an hour last night.
The solution you provided works flawlessly with the rest of the code. Marking as solved

Interesting. Do you just not like pointers, or would you take a moment to say in what language there exist pointers that are not awful inventions?

I find the pointers in C, at least, to be very well done, at least I have since I got my head around them.

Did C++ do something around pointers that messed them up for you? I still just use them like I did in C for the most part not even realizing I am programming in C++.

For fun I googled

 beauty of pointers in c

and yes, it seems ppl like them.

a7

And how long did that process take, from start to finish? Be honest.

C is notorious for the poor handling of multidimensional arrays, given that it is based on the concept of pointers, and pointer arithmetic.

I will attempt to answer your question. Pointers are identical to assembly language for any computer that has instructions to put an address in a register and use that value to point to something of interest. In fact most assembly would be a terrible mess without that capability.

When I worked through K&R in a crash effort to be able to say with a straight face that I could do some work that came my way, I already knew about pointers, arrays and all that.

So the actual part of learning how C does it did not take long. I found the section or chapter or whatever to be clear and concise; I found the entire treatment of arrays and pointers to be entirely logic and bordering on brilliant. For affording the capabilities they do, C pointers are about as simple as it can get.

I think ppl who have real trouble are the ones that just throw asterisks and ampersands at things in an effort to get the results they want

But yeah, I do feel for anyone who hasn't a clue and notices some ppl doing cool things with Arduinos and C++. All this stuff gets so much easier as years of playing with it go by.

I guess I was just stricken by your clear loathing of pointers in C++. There are awful inventions, in programming languages and the real world. I don't think pointers qualify.

a7

I have no problem with pointers. My major problem is the implementation of multidimensional arrays, which is truly awful.

I learned computing doing scientific programming in Fortran, a language in which it is easy to write a function that performs an operation on matrices of arbitrary size and numbers of dimensions. Then I was forced to translate some of that work into C, and that was a nightmare.

I simply could not, and still don't, understand why anyone would think it is a good idea to treat one dimension of an array as something fundamentally different than another dimension.

Imagine a coordinate system in which Y is a pointer to a collection of X values. Makes no sense whatsoever.

Because, at one time, when computers were memory limited to the extreme, one dimension would be a disk cylinder, another dimension would be a track on that cylinder and another dimension would be a displacement on that track. Having them memory of today makes it a whole lot easier.

Sorry, I don't buy that rationalization.

Fortran ran on machines of very limited size, and the geometry of disk storage was never considered in the design of the programming language.

An IBM 1440 disk system max memory was 16,000 memory locations, bytes and words had not been invented, yet. I had to squeeze a 20 k program into 16k. The array was the memory killer, and it had to be done for a payroll system, of all things. Long before Fortran.

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