array of pointers (pointer memory reqs?)

Starting on a plotter type project and trying to assess if I can make it stand alone rather than tethered (to a PC).

The situation is I want to store the plotting instructions for a very simplified stick font. The req. data is along the lines of: 41; 18; 1,0 9,21 17,0; 4,7 14,7 - that's for the letter 'A'. I haven't figured out a data format yet - likely a simple array of ints.

What I am wondering is if once I have defined my char plot arrays, can I then define 'words' through pointers to those arrays? My goal/hope is that once the byte heavy font plot data is defined (and stored in PROGMEM), I will still have enough memory left to define lots of "words" (arrays of pointers to the plot data).

Does this make any sense? :wink:

Simple pseudo code (plot data is fake) but this compiles:

int A[] = {41,18,1,0, 9,21, 17,0, 4,7, 14,7};
int B[] = {23, 55, 44, 21, 77, 88, 41,18,1,0, 9,21, 17,0, 4,7, 14,7};
int C[] = {41,18,1,0, 9,21, 17,0, 4,7,33, 22, 14,7};
int T[] = {41,18,1,0, 9,21, 4,7, 14,7};

int* cat[3] = {C, A, T};
int* bat[3] = {B, A, T};


void setup() {
 
}

void loop() {
 int**  currentWord = cat;
}

Looks reasonable to me. The hardest part will be to correctly dereference currentword, given that you have no idea the size of the arrays involved, from the pointer. If there were some obvious end-of-data marker in each array, you could detect that.

For instance, add a NULL to the end of cat. If the values in A[] will all be positive, a negative value could indicate the end of data. Alternatively, the first value in A[] could be the number of values to follow.

Of course this makes sense as a plotter works somehow similar although it often has bigger memory than an Arduino. But OK.

I should add a length to the array's. e.g the length of the array T is 5
int T[] = {5, 41,18,1,0, 9,21, 4,7, 14,7};

To spell words I would use normal strings and write a small interpreter. Something like below

void setup()
{
  Serial.begin(19200);
}

void loop()
{
  String s = "cat";
  interpret(s); 
  while(1);
}

int A[] = {41,18,1,0, 9,21, 17,0, 4,7, 14,7};
int B[] = {23, 55, 44, 21, 77, 88, 41,18,1,0, 9,21, 17,0, 4,7, 14,7};
int C[] = {41,18,1,0, 9,21, 17,0, 4,7,33, 22, 14,7};
int T[] = {41,18,1,0, 9,21, 4,7, 14,7};

void interpret(String s)
{
  for (byte i=0; i< s.length(); i++)
  {
    switch (s[i])
    {
      case 'a' : Draw(A); break;
      case 'b' : Draw(B); break;
      case 'c' : Draw(C); break;
      case 't' : Draw(T); break;
      default: break;
    }
  }
}

void Draw(int * p)
{
  int len = p[0];
  for (byte i=0; i< len; i++)
  {
    // draw the vectors.
  }
}

As you have 26 letters you use quite some RAM for the vectors. This can be circumvented by dividing the letters in elementary vectors. That means the code above would change like this (pseudocode)

case 'a' : Draw(/); Draw(-); Draw(); break;

Thanks for the replies! I agree, it is completely plotter-esque in terms of reinventing that wheel - except for the memory limits on the Arduino. I've been digging through what I can find on the web @ plotter char sets, etc.

Since I'd like this to be stand alone, I'm trying to get a rough sense of what the limits are (in terms of memory and my coding ability... :wink: I have a mega I can use so I have some space.

The reason for the array of 'word' pointers is so that I can define a sort of vocabulary and construct sentences through various code-based rules. I figured staying away from the String class would be best in terms of memory.

Coming up with 'elementary' vectors is an interesting idea.

A follow up question:

--dereferencing; I get the idea of it but have never done it. What should I look up @ that (C method, etc.)? I can easily add a length indicator to each array in my data structure.

EDIT: just looked at this page: Arduino Playground - Pointer Resource - and maybe I don't understand dereferencing.

Will I run into problems with 'word' arrays of different lengths?:

// pseudo code

void loop() {
 int**  currentWord;


 currentWord = cat;

 draw(currentWord);

 currentWord = elephant;

 draw(currentWord);

//etc.
}