Go Down

Topic: Scrolling Text, what's am I doing wrong? (Read 453 times) previous topic - next topic

Maramor

Feb 19, 2012, 07:51 am Last Edit: Feb 19, 2012, 08:00 am by CrossRoads Reason: 1
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 :).
Code: [Select]

/*
 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)
-Matt
Microsoft SQL Server DBA
Novice /w Electronics

Joy

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

Maramor

Sorry, text comes in from right and scrolls left.
-Matt
Microsoft SQL Server DBA
Novice /w Electronics

Joy

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..??

Maramor

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?
-Matt
Microsoft SQL Server DBA
Novice /w Electronics

Go Up