LCD new text at top

Hi everyone, I'm trying to create a simple code to have a char array get printed to the first line of an LCD with new information. Then when more new information comes up I want it published to the first line and what was previously on the first line get moved down to the second line so forth and so on. I'm having an issue with char arrays mainly because I am so new with arduino I don't quite understand them. Hopefully you can help me out. Here is a super simplified version of my code.

#include <LiquidCrystal_I2C.h>
char Line1[21];
char Line2[21];
char Line3[21];
char Line4[21];
char NewInfo[21];

LiquidCrystal_I2C lcd(0x27, 20, 4);

void setup()
{
  Serial.begin(115200);
  lcd.begin();
  lcd.backlight();
  lcd.clear();
}

void LCDPrint()
{
  Line4[21] = Line3[21];
  Line3[21] = Line2[21];
  Line2[21] = Line1[21];
  Line1[21] = NewInfo[21];
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print(Line1);
  lcd.setCursor(0, 1);
  lcd.print(Line2);
  lcd.setCursor(0, 2);
  lcd.print(Line3);
  lcd.setCursor(0, 3);
  lcd.print(Line4);
}

void loop()
{
NewInfo[21] = {'Test1'};
LCDPrint();
delay(1000);
NewInfo[21] = {'Test2'};
LCDPrint();
delay(1000);
NewInfo[21] = {'Test'};
LCDPrint();
delay(1000);
NewInfo[21] = {'Test4'};
LCDPrint();
delay(1000);
}

Tell us what this line of code does ?

The end result is it should print “Test1” on the top line then one second later shift it down the print “Test2” at the top and continue on.

NewInfo[21] = {'Test1'};

Is not the same as

NewInfo[21] = {“Test1”};

However, Google strcpy()

I tried it both ways, however I will google the string copy command.

https://www.cplusplus.com/reference/cstring/strcpy/

strcpy (NewInfo,"Test1");

Amazing thanks. I got it working.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.