need help (no operator "=" matches these operands)

hi, good day. i am trying to upload this code to my arduino mega 2560 compatible board. i am using visual micro, its loads to the board but the button keys on my lcd shield doesn't work, except one button, the select button key. kindly please point me in the right direction on how to fix this. thank you very much.

see attachment for reference please.

Post complete code in code tag.
Post complete error message in code tag also.

For informed help, please read and follow the directions in the "How to use this forum" post.

i cannot put the whole code, it exceeds the maximum allowed chcaracter. i will attach it as txt file instead.

but here's a portion which i think is the culprit.

 //UI Menus
 if (Key == 0 || Key == 408){
 //Left & Right
 if (screenName == "DATETIME"){
 matrix = {
 { { 1, 1 }, { 4, 4 }, { 10, 10 }, { 13, 13 } },
 { { 3, 3 }, { 6, 6 }, { 13, 13 } }
 };
 }
 if (screenName == "NEW"){
 matrix = {
 { { 0, 7 } },
 { { 11, 11 } }
 };
 if (Key == 0){
 cropRename(NULL);
 lcd.blink();
 }
 }
 if (screenName == "OPEN"){
 matrix = {
 { { 0, 0 } },
 { { 1, 1 }, { 9, 9 } }
 };
 }
 if (screenName == "RESET"){
 matrix = {
 { {0, 0} },
 { { 1, 1 }, { 11, 11 } }
 };
 }
 if (screenName == "DELETE") {}
 if (screenName == "STATUS") {
 matrix = {
 { { 8, 8 } },
 { { 1, 1 }, { 13, 13 } }
 };
 }
 if (screenName == "ECRANGE") {
 matrix = {
 { { 3, 3 }, { 8, 8 }, { 15, 15 } },
 { { 1, 1 }, { 11, 11 } }
 };
 }

hydroponic code.txt (24.5 KB)

matrix = {
 { { 1, 1 }, { 4, 4 }, { 10, 10 }, { 13, 13 } },
 { { 3, 3 }, { 6, 6 }, { 13, 13 } }
 };

You cannot set value of matrix this way anymore.
You can only do this in the declaration.
To set values for it after, you must use nested for() loop.

I am kind of lost now. maybe you can show me how, just a quick one, please. im confused as to where to start the nested for loop (). sorry

“Anymore”? Did that ever work?
I Suggest progmem constant arrays, and memcpy_p()

i dont know what happened, but visual studio just crashed and i am re installing now. i cannot do this code on arduino ide, too complex for the arduino ide. anyways, thanks for the help, but i just have to wait til i can finish the download of Visual Studio. I am from the Philippines, internet is not so good here. sigh.

blue1209:
i dont know what happened, but visual studio just crashed and i am re installing now. i cannot do this code on arduino ide, too complex for the arduino ide. anyways, thanks for the help, but i just have to wait til i can finish the download of Visual Studio. I am from the Philippines, internet is not so good here. sigh.

The code I posted did not work. I tried to cross it out but instead I deleted the post.
You must do something like this now:

const byte matrixA[][2] = 
 { { 1, 1 }, { 4, 4 }, { 10, 10 }, { 13, 13 },
 { 3, 3 }, { 6, 6 }, { 13, 13 }};

const byte matrixB[][2] ={{ 0, 7 }, {11, 11 }};

void loop()
{
   ...
  if (screenName == "DATETIME"){
      //use matrixA here
  }

  if (screenName == "NEW"){
   //use matrixB here
  }
   ...
}

The code cannot be too complex for Arduino Ide, or if it is all this work is useless, because it will never work. Now you explain us what you want to do and attach the code like allegate. So we can see it

What data type is "matrix"? (Sigh. I do web search for DROMatic, which I find GitHub - drolsen/DRO-Matic: Fully Automated Hydroponic OS for DIY DRO-Matic cabinets - Nutrient dosing, irrigation, topoffs, timers, EC & pH drift fixing., which has screens.cpp with:

vector<vector<vector<byte>>> matrix;

I ... am not sure if there is an easy fix here; the vector is a variable length thing, so copying it is more complicated than if it were just an array. Maybe. And I'm not sure how C++ objects interact with PROGMEM. And there don't seem to be any useful comments in the code explaining WTF it's trying to do. (Sigh.)

If you have sufficient RAM free in the project, you can probably change code from:

	//UI Menus
	if (Key == 0 || Key == 408){
		//Left & Right
		if (screenName == "DATETIME"){
			matrix = {
				{ { 1, 1 }, { 4, 4 }, { 10, 10 }, { 13, 13 } },
				{ { 3, 3 }, { 6, 6 }, { 13, 13 } }
			};
		}
		if (screenName == "NEW"){
			matrix = {
				{ { 0, 7 } },
				{ { 11, 11 } }
			};
			if (Key == 0){
				cropRename(NULL);
				lcd.blink();
			}
		}
		if (screenName == "OPEN"){

to something more like:

	    if (screenName == "DATETIME"){
		static vector<vector<vector<byte>>> datmatrix = {
		    { { 1, 1 }, { 4, 4 }, { 10, 10 }, { 13, 13 } },
		    { { 3, 3 }, { 6, 6 }, { 13, 13 } }
		};
		matrix = datmatrix;
	    }
	    if (screenName == "NEW"){
		static vector<vector<vector<byte>>> newmatrix = {
		    { { 0, 7 } },
		    { { 11, 11 } }
		};
		matrix = newmatrix;
		if (Key == 0){
		    cropRename(NULL);
		    lcd.blink();
		}
	    }

(Hmm. Actually, this should be pretty close to what the current code is doing, in terms of RAM usage/etc.)

But what do you want to do? In your title there is "no operator "=" matches these operands". You can use = in twoo ways:
Something=something else
Whitch arrays
Something[number]=something else
Or
Something = somethingelse[number]
Or
Something [number] =somethimgelse [number]
You can never use operations behiend the =, exept into the [].
If you are using multidimentional arrays you have to indicate all the index like the first.

And if = doesn't work nothing can go.
Remember that = is assegnament and == is control

1 Like

Just wrap your array in a struct. The downside is that you have to use double braces for initialization, but now you can use array assignment:

Code:

---



```
template <class T, size_t N>
struct Array {
T data[N];

T &operator[](size_t index) { return data[index]; }
   const T &operator[](size_t index) const { return data[index]; }
   T *begincolor=#000000[/color] { return &data[0]; }
   const T *begincolor=#000000[/color] const { return &data[0]; }
   T *endcolor=#000000[/color] { return &data[N]; }
   const T *endcolor=#000000[/color] const { return &data[N]; }
};

Array<Array<Array<byte, 2>, 4>, 2> matrix = {{
   {{
     { 1, 1 }, { 4, 4 }, { 10, 10 }, { 13, 13 }
   }},
   {{
     { 3, 3 }, { 6, 6 }, { 13, 13 },
   }},
}};
```

|

template <class T, size_t N>
struct Array {
    T data[N];

    T &operator[](size_t index) { return data[index]; }
    const T &operator[](size_t index) const { return data[index]; }
    T *begin() { return &data[0]; }
    const T *begin() const { return &data[0]; }
    T *end() { return &data[N]; }
    const T *end() const { return &data[N]; }
};

Array<Array<Array<byte, 2>, 4>, 2> matrix = {{
    {{ 
      { 1, 1 }, { 4, 4 }, { 10, 10 }, { 13, 13 } 
    }},
    {{ 
      { 3, 3 }, { 6, 6 }, { 13, 13 },
    }},
}};

template <class T> void print(Print &p, const T &value, const uint8_t indent = 0) {
  for (uint8_t i = 0; i < indent; i++)
    p.print(' ');
  p.println(value);
}

template <class T, size_t N> void print(Print &p, const Array<T, N> &array, const uint8_t indent = 0) {
  for (uint8_t i = 0; i < indent; i++)
    p.print(' ');
  p.println('{');
  for (const T &el : array)
    print(p, el, indent + 2);
  for (uint8_t i = 0; i < indent; i++)
    p.print(' ');
  p.println('}');
}

void setup() {
  Serial.begin(115200);
  while(!Serial);
  print(Serial, matrix);

  matrix = {{
      {{ 
        { 2, 2 }, { 3, 3 }, { 4, 4 }, { 5, 5 } 
      }},
      {{ 
        { 6, 6 }, { 7, 7 }, { 8, 8 }, { 9, 9 }
      }},
  }};
  print(Serial, matrix);
}

void loop() {}

However, I think that it would be better to rethink the architecture of your program, as this approach seems very error-prone.

Pieter