Pages: [1]   Go Down
Author Topic: Scrolling Text, what's am I doing wrong?  (Read 429 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 19
If you can dream building it, you can build it!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 smiley.
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");
}

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)
« Last Edit: February 19, 2012, 02:00:32 am by CrossRoads » Logged

-Matt
Microsoft SQL Server DBA
Novice /w Electronics

INDIA
Offline Offline
Sr. Member
****
Karma: 0
Posts: 382
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
Newbie
*
Karma: 0
Posts: 19
If you can dream building it, you can build it!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Sorry, text comes in from right and scrolls left.
Logged

-Matt
Microsoft SQL Server DBA
Novice /w Electronics

INDIA
Offline Offline
Sr. Member
****
Karma: 0
Posts: 382
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
Newbie
*
Karma: 0
Posts: 19
If you can dream building it, you can build it!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

-Matt
Microsoft SQL Server DBA
Novice /w Electronics

Offline Offline
Newbie
*
Karma: 0
Posts: 19
If you can dream building it, you can build it!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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();
        }
      }
    }
   } 
}
« Last Edit: February 19, 2012, 04:27:16 am by Maramor » Logged

-Matt
Microsoft SQL Server DBA
Novice /w Electronics

INDIA
Offline Offline
Sr. Member
****
Karma: 0
Posts: 382
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hummm:)
Good job dude... smiley
Logged

Greenville, IL
Offline Offline
Edison Member
*
Karma: 15
Posts: 1330
Warning Novice on board! 0 to 1 chance of errors!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

 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.

Code:
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
Logged


Greenville, IL
Offline Offline
Edison Member
*
Karma: 15
Posts: 1330
Warning Novice on board! 0 to 1 chance of errors!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


 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
Code:
for (x = 0; x < 16; x++)
{
do stuff using x
}

loop2
Code:
for (x = 16; x > 0; x--)
{
do stuff using x
}
Logged


Pages: [1]   Go Up
Jump to: