Pages: [1]   Go Down
Author Topic: Formatting the output, JHD204A LCD  (Read 1058 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello, i'm new here and i have a question.
I connected the JHD204a LCD display to Arduino Duemilanove. I get positioning the cursor, and printing simple things. Now i started another project and i need help. Is there any way to print something like this
Code:
The values are: X;Y;Z;//X,Y,Z are variables

I started like this:
Code:
#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int x = 0;
int y = 0;
int z = 0;

void setup() {
  lcd.begin(20, 4);
  lcd.print("Hello World");
}

void loop() {
  lcd.setCursor(0, 1);
  x=millis()/1000;
  lcd.print(x);
  lcd.setCursor(2, 1);
  lcd.print(";");
  y=x*2;
  lcd.setCursor(3, 1);
  lcd.print(y);
  z=y*2;
  lcd.setCursor(5, 1);
  lcd.print(";");
  lcd.setCursor(6, 1);
  lcd.print(z);
}
This prints pretty much what i need, until some of the variables reach 3-digits, then print overlaps. Is there any way to automatically move the ";" markers to make room for more digits. Thx in advance smiley
Logged

Dee Why NSW
Offline Offline
Full Member
***
Karma: 5
Posts: 206
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have wondered the same thing.  Like having a variable in the command -  lcd.setCursor(p, 1); and converting data into strings of a fixed length.
I have found that using leading zeros, like

  lcd.print(minute);
  lcd.print(":");
     if ((second) < 10)
  {
    lcd.print("0");
  };
   lcd.print(second);

and junk-clearing blanks like

  lcd.print("     ");

suffice so far.....
Logged

Offline Offline
Edison Member
*
Karma: 116
Posts: 2205
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What I do in those cases is to form a string / buffer and send that buffer to the lcd in one shot.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for quick reply. I will try this.
Logged

Pages: [1]   Go Up
Jump to: