Multi-dimensional array in PROGMEM (Arduino Noob)

Hello,

I can't get the search function on this forum to give me anything but errors, so I appologize up front if this is already covered somewhere.

I am building a Halloween costume with star patterns of blue LEDs. Each star is a matrix of 4 bars with 4 concentric circles. The bars provide positive and the circles provide negative. Long story short, the program is too big, so I need to put some arrays into PROGMEM:

#include <avr/pgmspace.h>

int ledState = LOW;
int arrayLength = 25;
prog_uint16_t starPatterns[] PROGMEM = {13,21,25,27,13,39,85,217,84,38,12,20,24,26,12,20,24,26,12,104,138,217,85,39,13};
prog_uint16_t speedSettings[] PROGMEM = {1,1,1,1,2,2,2,2,2,2,2,1,1,1,1,1,1,1,2,2,2,2,2,2,2};
int speedArray[] = {300, 90, 50};
prog_uint16_t sidePatterns[][4] PROGMEM = {{1, 1, 1, 1}, {1, 1, 1, 0}, {1, 1, 0, 1}, {1, 1, 0, 0}, {1, 0, 1, 1}, {1, 0, 1, 0}, {1, 0, 0, 1}, {1, 0, 0, 0}, {0, 1, 1, 1}, {0, 1, 1, 0}, {0, 1, 0, 1}, {0, 1, 0, 0}, {0, 0, 1, 1}, {0, 0, 1, 0}, {0, 0, 0, 1}, {0, 0, 0, 0}};
prog_uint16_t mainPatterns[][2] PROGMEM = {{0, 1}, {1, 0}, {0, 2}, {2, 0}, {0, 3}, {3, 0}, {0, 4}, {4, 0}, {0, 5}, {5, 0}, {0, 6}, {6, 0}, {0, 7}, {7, 0}, {0, 8}, {8, 0}, {0, 9}, {9, 0}, {0, 10}, {10, 0}, {0, 11}, {11, 0}, {0, 12}, {12, 0}, {0, 13}, {13, 0}, {0, 14}, {14, 0}, {1, 2}, {2, 1}, {1, 3}, {3, 1}, {1, 4}, {4, 1}, {1, 5}, {5, 1}, {1, 6}, {6, 1}, {1, 7}, {7, 1}, {1, 8}, {8, 1}, {1, 9}, {9, 1}, {1, 10}, {10, 1}, {1, 11}, {11, 1}, {1, 12}, {12, 1}, {1, 13}, {13, 1}, {1, 14}, {14, 1}, {2, 3}, {3, 2}, {2, 4}, {4, 2}, {2, 5}, {5, 2}, {2, 6}, {6, 2}, {2, 7}, {7, 2}, {2, 8}, {8, 2}, {2, 9}, {9, 2}, {2, 10}, {10, 2}, {2, 11}, {11, 2}, {2, 12}, {12, 2}, {2, 13}, {13, 2}, {2, 14}, {14, 2}, {3, 4}, {4, 3}, {3, 5}, {5, 3}, {3, 6}, {6, 3}, {3, 7}, {7, 3}, {3, 8}, {8, 3}, {3, 9}, {9, 3}, {3, 10}, {10, 3}, {3, 11}, {11, 3}, {3, 12}, {12, 3}, {3, 13}, {13, 3}, {3, 14}, {14, 3}, {4, 5}, {5, 4}, {4, 6}, {6, 4}, {4, 7}, {7, 4}, {4, 8}, {8, 4}, {4, 9}, {9, 4}, {4, 10}, {10, 4}, {4, 11}, {11, 4}, {4, 12}, {12, 4}, {4, 13}, {13, 4}, {4, 14}, {14, 4}, {5, 6}, {6, 5}, {5, 7}, {7, 5}, {5, 8}, {8, 5}, {5, 9}, {9, 5}, {5, 10}, {10, 5}, {5, 11}, {11, 5}, {5, 12}, {12, 5}, {5, 13}, {13, 5}, {5, 14}, {14, 5}, {6, 7}, {7, 6}, {6, 8}, {8, 6}, {6, 9}, {9, 6}, {6, 10}, {10, 6}, {6, 11}, {11, 6}, {6, 12}, {12, 6}, {6, 13}, {13, 6}, {6, 14}, {14, 6}, {7, 8}, {8, 7}, {7, 9}, {9, 7}, {7, 10}, {10, 7}, {7, 11}, {11, 7}, {7, 12}, {12, 7}, {7, 13}, {13, 7}, {7, 14}, {14, 7}, {8, 9}, {9, 8}, {8, 10}, {10, 8}, {8, 11}, {11, 8}, {8, 12}, {12, 8}, {8, 13}, {13, 8}, {8, 14}, {14, 8}, {9, 10}, {10, 9}, {9, 11}, {11, 9}, {9, 12}, {12, 9}, {9, 13}, {13, 9}, {9, 14}, {14, 9}, {10, 11}, {11, 10}, {10, 12}, {12, 10}, {10, 13}, {13, 10}, {10, 14}, {14, 10}, {11, 12}, {12, 11}, {11, 13}, {13, 11}, {11, 14}, {14, 11}, {12, 13}, {13, 12}, {12, 14}, {14, 12}, {13, 14}, {14, 13}, {14, 14}, {13, 13}, {12, 12}, {11, 11}, {10, 10}, {9, 9}, {8, 8}, {7, 7}, {6, 6}, {5, 5}, {4, 4}, {3, 3}, {2, 2}, {1, 1}, {0, 0}, {15, 15}, {15, 14}, {15, 13}, {15, 12}, {15, 11}, {15, 10}, {15, 9}, {15, 8}, {15, 7}, {15, 6}, {15, 5}, {15, 4}, {15, 3}, {15, 2}, {15, 1}, {15, 0}, {14, 15}, {13, 15}, {12, 15}, {11, 15}, {10, 15}, {9, 15}, {8, 15}, {7, 15}, {6, 15}, {5, 15}, {4, 15}, {3, 15}, {2, 15}, {1, 15}, {0, 15}};

void setup() {
for (int thisPin = 2; thisPin < 10; thisPin++) {
pinMode(thisPin, OUTPUT);
}
}

void loop()
{
for (int playHead = 0; playHead < arrayLength; playHead++){
int currentSpeed = speedArray[speedSettings[playHead]];
int currentPattern = starPatterns[playHead];
for (int thisPattern = 0; thisPattern < 4; thisPattern++){
int thisBar = thisPattern+2;
int myBarMain=mainPatterns[currentPattern][0];
int myBarSide = sidePatterns[myBarMain][thisPattern];
if (myBarSide == 1)
ledState = HIGH;
else
ledState = LOW;
digitalWrite(thisBar, ledState);
int thisCircle = thisPattern+6;
int myCircleMain=mainPatterns[currentPattern][1];
int myCircleSide = sidePatterns[myCircleMain][thisPattern];
if (myCircleSide == 1)
ledState = HIGH;
else
ledState = LOW;
digitalWrite(thisCircle, ledState);
}
delay(currentSpeed);}
}

I am not getting an error when I compile so I am assuming that the arrays are going into PROGMEM correctly, but the examples on the learning section of the Arduino site are very confusing. All I want to do is to call back specific records from the arrays per the loops later in the program. Any help would be greatly appreciated!

I wasn't able to put a link in my first post, so hopefully this will work. I mocked-up what the star should do in Flash (www.lassard.com/OMS) to give you an idea of what I am going for.

A couple of things:

  1. you should just use 8 bit values since your data points don't exceed 256.

  2. you need to make your main code read from the program space.

So,

  1. e.g.
byte mainPatterns[][2] PROGMEM = {{0, 1}, {1, 0}, ... etc.
  1. e.g.
byte myBarMain = pgm_read_byte(&(mainPatterns[currentPattern][0]));

etc... for the other reads

Try that.

b

(FYI - byte is typedef'd to uint8_t in wiring.h)

You might use Mikal Hart's Flash library - it simplifies storing and accessing data in Flash memory.
http://arduiniana.org/libraries/flash/

Thanks, BHAGMAN, that is exactly what I was looking for!
Once I get the hang of that, I'm going to try the Professor's idea as well. This forum rocks!

I'm having trouble setting up a 2d array in progmem. When I compile the code below...

#include <avr/pgmspace.h>

byte numbers[5][3] PROGMEM =
{
  {1, 2, 3},  
  (4, 5, 6},  // it highlights this when it gives the error
  {7, 8, 9},  
  {10, 11, 12},  
  {13, 14, 15} 
};

I get an error: expected ')' before '}' token
I have some more code after this, but it never gets there. Anybody have any ideas what's going wrong?

  (4, 5, 6},  // it highlights this when it gives the error

Did you really look at that line that the system flagged?

  [glow]([/glow]4, 5, 6},  // it highlights this when it gives the error

Been there, done that. Simple mistakes can seem to be OK whether you look once or a hundred times.. On some screens at some resolutions ( doesn't show up much different than {. Not to my tired old eyes.

Regards,

Dave

Thanks so much! I've been working on this too long I think. I must have looked at it a thousand times today.

My opinion: It's always OK to get someone else to take a look at things. Speaking for myself, I can remember wasting time overlooking "obvious" stuff like this, and I promise that I will never, ever (well almost never) make fun of people's mistakes (except my own, of course).

Regards,

Dave