Storing strings in a list and then display all the stored strings

First of all, this is just a rough idea and I don't know where to start. So, don't flame me by asking for my code. I haven't made one. What I currently need right now is some kind of guide to implement what the subject suggests. But I will be writing a few snippets that come to my mind.

So, basically I have a data coming from a serial which is input by the user.

if (data == 100)
{
  lcd.setCursor(0,0);
  lcd.print("ITEM 100");
}

else if (data == 101)
{
  lcd.setCursor(0,0);
  lcd.print("ITEM 101");
}

Now, how do I save the strings "ITEM 100" to a list?

And then with a push of a button, the list will be displayed like this

ITEM 100
ITEM 101

Additionally, I want to be able to move my cursor through the list by pressing up/down button, remove an item by another button. But that's too much to demand right now. I would love to start by saving the strings into a list.

Note that the string is not coming from the serial input. The serial input just determines what to strings to be displayed.

I have looked through a few Menu System but I would like to get ideas from the community also.

Thanks in advance.

cyberjupiter:
First of all, this is just a rough idea and I don't know where to start. So, don't flame me by asking for my code. I haven't made one. What I currently need right now is some kind of guide to implement what the subject suggests. But I will be writing a few snippets that come to my mind.

So, basically I have a data coming from a serial which is input by the user.

if (data == 100)

{
 lcd.setCursor(0,0);
 lcd.print("ITEM 100");
}

else if (data == 101)
{
 lcd.setCursor(0,0);
 lcd.print("ITEM 101");
}




Now, how do I save the strings "ITEM 100" to a list? 

And then with a push of a button, the list will be displayed like this



ITEM 100
ITEM 101




Additionally, I want to be able to move my cursor through the list by pressing up/down button, remove an item by another button. But that's too much to demand right now. I would love to start by saving the strings into a list.

Note that the string is not coming from the serial input. The serial input just determines what to strings to be displayed.

I have looked through a few Menu System but I would like to get ideas from the community also.

Thanks in advance.

This shouldn't be impossible but you are limited in memory space on an uno so external storage may be needed like a flash drive.
you will get very familiar with strcpy ( )
I could also see you using memcpy ( ) as well
Also pointer arrays to strings:
char * MyList [ 25 ] ; // stores the starting memory locations of 25 strings
and/or
char MyStrings [ 25 ] [ 17 ]; // 25 arrays of 17 char's (16 for text plus one for the '\0' null string terminator)
This is just a direction I would start looking to achieve your goal you
Z

cyberjupiter:

if (data == 100)

{
  lcd.setCursor(0,0);
  lcd.print("ITEM 100");
}

else if (data == 101)
{
  lcd.setCursor(0,0);
  lcd.print("ITEM 101");
}

Enjoy the typing :smiley:

As @zhomeslice indicated, you can use an array.

// N text strings with a max length of 24 each
char mytext[][25] = 
{
  "hello",
  "world"
};

Next you can e.g. iterate through the array elements using e.g. a for loop to display all text strings.

  for (int cnt = 0; cnt < sizeof(mytext) / sizeof(mytext[0]); cnt++)
    Serial.println(mytext[cnt]);

Note the use of cnt as an index into the array to 'pick' the text to be displayed. The way it is used as an index will be important for your application.

Please note @zhomeslices comment about the amount of memory that you have available.

zhomeslice:
you will get very familiar with strcpy ( )
I could also see you using memcpy ( ) as well

I don't (yet) see the need for those :wink: Regardless if RAM, EEPROM or external storage is used.

Hi, @sterretje.

Your example works great. But I come across two problems.

First, using for loop will iterate every strings in the array. The input from serial does not necessarily display all strings. It just need to display what the user has input in. For example, if the user input 100 and 101, then only "ITEM 100 and ITEM 101" should be displayed. Using for loop seems to display everything in the array.

Secondly, it works fine with serial monitor but when imported to LCD, the string is not printed in newline but instead, next to it.

Pardon me for being a newbie, but this is almost to what I need to achieve.

Thanks for the help though.

The code was just an example. You need to understand how it works and base your code on it. In your case you obviously don't need the for loop.

Clear lcd
Position cursor on first line, print mytext[cnt]
Position cursor on next line, print mytext[cnt+1]

sterretje:

// N text strings with a max length of 24 each

char mytext[][25] =
{
  "hello",
  "world"
};

why the wasteful fixed-width array? If this is a "Menu System" that suggests const-ness in these strings...

const char* myNames[] = {"hello", "world"};

if we are in the 100's of possible options, how about program space?