Scrolling Text, what's am I doing wrong?

OK OK OK, I have a 16x2 lcd setup on my Arduino duo, yahoo!!!
I am new to building electronics and the Arduino, yahoo!!!

I am playing with setting up the lcd and doing some basic things to get used to the the syntax.
While I was working on several things, I tried to set it up to scroll and almost have it working after several hours of syntax and logic research @ 2am I just don't get it. I don't see why it does not work.

The first line scrolls perfectly but the second line well gets all the way to the start of the string then pops back to the top row, otherwise does what I expect? Also there is probably a easier way to do this but one thing keeps leading to another :).

/* 
  The circuit:
 * LCD RS pin to digital pin 7
 * LCD Enable pin to digital pin 8
 * LCD D4 pin to digital pin 9
 * LCD D5 pin to digital pin 10
 * LCD D6 pin to digital pin 11
 * LCD D7 pin to digital pin 12
 * LCD R/W pin to ground
 * 10K resistor: ends to +5V and ground
 * wiper to LCD VO pin (pin 3)
 */

// include the library code:
#include <LiquidCrystal.h>

// global variables
int columns = 16;
int rows = 2; 

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

void setup() {
  // set up the LCD's number of columns and rows:
  lcd.begin(columns, rows);  
}

void loop() {
  scroll("0123456789");
}

void scroll(String msg) 
{
  int x = 0;
  int y = 0;
  int x1 = 0;
  String msg1;
  
  for (y = 0; y <= rows; y++) 
  {
    for (x = columns; x >= 0; x--) 
    {
      lcd.setCursor(x, y);      
      if (x != 0) 
      {
        lcd.print(msg);
        delay(500);
        lcd.clear();
      } else 
      {
        for (x1 = 0; x1 < msg.length(); x1++) 
        {
          msg1 = msg.substring(x1);
          lcd.print(msg1);
          delay(500);
          lcd.clear();
        } 
      }
    }
   }  
}

(code tags added by moderator)

Tell us correctly in what way do you want your text to scroll in your LCD...??

Sorry, text comes in from right and scrolls left.

On which row from which side...??

You mean on the top row it will scroll form right to left then when done it will scroll from left to right on the row 2

Or it will scroll together on both the rows..??
on row 1 right to left
on row 2 left to right

Both at the same time..??

Again, I apologize for over simplified answers.
Row 1 scrolls from right to left then row 2 scrolls from right to left. Basically the same function for row 1 happens on row 2.
My final product, I am trying to get it to look like it is wrapping and I should be able to pass any string.

What is baffling me is why my code does not handle row 2 the same as row 1?

It looks as if for some reason it loses x and y position.
Final code.

/* 
  The circuit:
 * LCD RS pin to digital pin 7
 * LCD Enable pin to digital pin 8
 * LCD D4 pin to digital pin 9
 * LCD D5 pin to digital pin 10
 * LCD D6 pin to digital pin 11
 * LCD D7 pin to digital pin 12
 * LCD R/W pin to ground
 * 10K resistor: ends to +5V and ground
 * wiper to LCD VO pin (pin 3)
 */

// include the library code:
#include <LiquidCrystal.h>

// global variables
int columns = 16;
int rows = 2; 

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

void setup() {
  // set up the LCD's number of columns and rows:
  lcd.begin(columns, rows);  
}

void loop() {
  scroll("0123456789",5);
  scroll("I love you Emily!",5);
}

void scroll(String msg,int intDelay) 
{
  int x = 0;
  int y = 0;
  int x1 = 0;
  String msg1;
  intDelay = intDelay*100;  //added delay control
  
  for (y = 0; y < rows; y++) 
  {
    for (x = columns; x >= 0; x--) 
    {
      lcd.setCursor(x, y);      
      if (x != 0) 
      {
        lcd.print(msg);
        delay(intDelay);
        lcd.clear();
      } else 
      {
        for (x1 = 0; x1 < msg.length(); x1++) 
        {
          msg1 = msg.substring(x1);
          lcd.setCursor(x, y); 
          lcd.print(msg1);
          delay(intDelay);
          lcd.clear();
        } 
      }
    }
   }  
}

Hummm:)
Good job dude... :slight_smile:

In this part of the code you are not incrementing x or y position. You print msg1 this many times..msg.length(), each time clearing the screen and starting back at the same x,y position.

The code above this code may work, but when you enter this for loop you must run it this many times...msg.length() and the rest of the code is unused during that period.

for (x1 = 0; x1 < msg.length(); x1++) 
        {
          msg1 = msg.substring(x1);
          lcd.setCursor(x, y); 
          lcd.print(msg1);
          delay(intDelay);
          lcd.clear();
        }

Maybe if you change your x1 variable to x, then each time you step through the for loop you will advance x+1 cursor position. At least I think this is what you want

This scrolling idea reminded me of the LED chaser program, except you have 16 leds wide by 2 leds tall.
Basically, the led chaser uses 2 for loops, the first loop increments (a variable) up and the second for loop decrements the same variable down.
LCD width == 16

loop1

for (x = 0; x < 16; x++) 
{
do stuff using x
}

loop2

for (x = 16; x > 0; x--)
{
do stuff using x
}