problems with changing values in an array \:-|

I'm having some difficulty with my recently written switch statement. :sweat_smile: I've been troubled by this for a while now and it's driving me crazy! :0 any help you can provide would be very appreciated! Here is the switch statement:

switch(mychar)
  {
    case 'a':
      TEMPdisp = {
        {0,1,1,0}, // row 1
        {1,0,0,1}, // row 2
        {1,1,1,1}, // row 3
        {1,0,0,1}, // row 4
        {1,0,0,1}, // row 5
        {1,0,0,1}  // row 6
      };
    break;
      
    case 'b':
      TEMPdisp = {
        {1,1,1,0}, // row 1
        {1,0,0,1}, // row 2
        {1,1,1,0}, // row 3
        {1,0,0,1}, // row 4
        {1,0,0,1}, // row 5
        {1,1,1,0}  // row 6
      };
    break;
      
    case 'c':
      TEMPdisp = {
        {0,1,1,0}, // row 1
        {1,0,0,1}, // row 2
        {1,0,0,0}, // row 3
        {1,0,0,0}, // row 4
        {1,0,0,1}, // row 5
        {0,1,1,0}  // row 6
      };
    break;
      
    default:
      TEMPdisp = {
        {1,0,1,0}, // row 1
        {0,1,0,1}, // row 2
        {1,0,1,0}, // row 3
        {0,1,0,1}, // row 4
        {1,0,1,0}, // row 5
        {0,1,0,1}  // row 6
      };
      Serial.print("Unsupported Character type. mychar = ");
      Serial.println(mychar);
    break;
  } // end of switch statement

Here is the error log: when it says, "expected ';' before '{' token" it directs me to the the "TEMPdisp = {" lines

functions.h:61: error: expected primary-expression before '{' token
functions.h:61: error: expected `;' before '{' token
_4x6_LED_Text_Scroller:76: error: expected `}' at end of input
_4x6_LED_Text_Scroller:76: error: expected `}' at end of input

If I am being unclear, just ask me. i'm going to be watching this thread closely, so expect a prompt reply. :)

You need to specify at least the first dimension of TEMPdisp.

TEMPdisp[6] = { …

[quote author=Morris Dovey link=topic=103423.msg775705#msg775705 date=1335579510] You need to specify at least the first dimension of TEMPdisp.

TEMPdisp[6][] = { ... [/quote] I tried doing that and it keeps giving me errors

case 'a':
      TEMPdisp[6][] = {
        {0,1,1,0}, // row 1
        {1,0,0,1}, // row 2
        {1,1,1,1}, // row 3
        {1,0,0,1}, // row 4
        {1,0,0,1}, // row 5
        {1,0,0,1}  // row 6
      };
    break;

It should be:

TEMPdisp[][4]

I don't think it's going to do you much good though. Declaring the array in the switch statement means that it is local to that switch statement and will disappear as soon as you leave it.

Pete

el_supremo: I don't think it's going to do you much good though. Declaring the array in the switch statement means that it is local to that switch statement and will disappear as soon as you leave it.

Pete

I'm actually not trying to declare the array in the switch statement. it has already been declared outside of the switch statement. I'm trying to modify already existing data of an array. Is this the way to do it?

TEMPdisp = { {0,1,1,0}, {1,0,0,1}, ...};

No you modify an array by specifically setting the values, not trying to redeclaire it again.

TEMPdisp[n] = 5;

Grumpy_Mike: No you modify an array by specifically setting the values, not trying to redeclaire it again.

TEMPdisp[n] = 5;

That is what I was afraid of... :( I'm finding the same thing everywhere else too. Programming in C says nothing of being able to do such a thing when not defining the variable. Thank you for the help! I really appreciate it!

You can get fancy if you have to change a lot of values and do it in a for loop.

My thanks to El Supremo for the correction, and my apologies to rtty21 for getting that backward.

This is a spectacularly inefficient way to store pixels for a character generator. I'd suggest re-thinking this solution so as to store eight pixels (or at least six) per byte. The savings would provide enough freed-up space for multiple tables that didn't need any of what you're trying to do here.

Using those tables directly from FLASH should free up a reasonable amount of RAM...

[quote author=Morris Dovey link=topic=103423.msg775746#msg775746 date=1335584489] This is a spectacularly inefficient way to store pixels for a character generator. I'd suggest re-thinking this solution so as to store eight pixels (or at least six) per byte. The savings would provide enough freed-up space for multiple tables that didn't need any of what you're trying to do here. [/quote] You're absolutely right. That's why I switched (no pun intended) to this:

      TEMPdata[5] = B0110; // row 5
      TEMPdata[4] = B1001; // row 4
      TEMPdata[3] = B1111; // row 3
      TEMPdata[2] = B1001; // row 2
      TEMPdata[1] = B1001; // row 1
      TEMPdata[0] = B1001; // row 0

I could be even more efficient and store two rows together, but I do like the readability! maybe i'll change it later when my 4x6 LED matrix project gets big enough to warrant sacrificing readability for memory usage.

All in all, I'm happy with reducing my array memory usage by a factor of 4.

Thanks to everyone who helped me with this! Thank you: --Morris Dovey --el_supremo --Grumpy_Mike