Go Down

Topic: Global variable value changes mysteriously between initialization and setup() (Read 874 times) previous topic - next topic

gardner


Code: [Select]

char phoneBook[ 2 ][ 6 ][ 13 ] = {
char callerNames[ 2 ][ 6 ][ 6 ] = {
char smsCommands[ 3 ][ 10 ] = {



These could and should all be placed in PROGMEM.  See

http://www.arduino.cc/en/Reference/PROGMEM


AWOL

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

snugRugBug

Well, I used F() on a bunch of my strings, and callsToday[ 0 ] is now 0, the way it should be.
As for the PROGMEM, I'm reading about it now, and it seems wonderful, but also complicated. It's going to take me a while to learn this.
Maybe someone (if they're feeling extremely charitable) can send me some example code for converting my 3d char arrays to PROGMEM arrays?
I've googled it, and found some info, but to make sense of it all is going to be quite a task...

snugRugBug

OK, I'm busy playing with PROGMEM, but I have 1 question:
As shown below, you declare and initialise all the prog_char arrays, and then place them into the structure. Is there a shorthand way of doing this?
Maybe something along the lines of

char[][3] list = { "aq", "er", "qw" } ;

instead of

char[3] str1 = "aq";
char[3] str2 = "er";
char[3] str3 = "qw";
char[][3] list = { str1, str2, str3 } ;

?

Code: [Select]

prog_char string_0[] PROGMEM = "+2xxxxxxxxx3";   // "String 0" etc are strings to store - change to suit.
prog_char string_1[] PROGMEM = "+2xxxxxxxxx0";
prog_char string_2[] PROGMEM = "+2xxxxxxxxx9";
prog_char string_3[] PROGMEM = "+2xxxxxxxxx4";
prog_char string_4[] PROGMEM = "+2xxxxxxxxx6";
prog_char string_5[] PROGMEM = "+2xxxxxxxxx6";
prog_char string_6[] PROGMEM = "+2xxxxxxxxx4";   // "String 0" etc are strings to store - change to suit.
prog_char string_7[] PROGMEM = "+2xxxxxxxxx4";
prog_char string_8[] PROGMEM = "+2xxxxxxxxx5";
prog_char string_9[] PROGMEM = "eeeeeeeeeeee";
prog_char string_a[] PROGMEM = "eeeeeeeeeeee";
prog_char string_b[] PROGMEM = "eeeeeeeeeeee";

// Then set up a table to refer to your strings.

PROGMEM const char *string_table[ 2 ][ 6 ] =    // change "string_table" name to suit
{ { 
  string_0,
  string_1,
  string_2,
  string_3,
  string_4,
  string_5 },
{
  string_6,
  string_7,
  string_8,
  string_9,
  string_a,
  string_b
}
};

Go Up