Pages: [1]   Go Down
Author Topic: LCD 2 Line messages + extra data  (Read 1046 times)
0 Members and 1 Guest are viewing this topic.
The Netherlands
Offline Offline
Sr. Member
****
Karma: 4
Posts: 331
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi looks so simple but.

I like to have more then a hello world text in the display.
What I need is 3 characters with behind it a space and the data comming from a strinf which are max 3 digits.
I tried several things to add behind this standard code.
Code:
  lcd.clear();
  lcd.begin(16, 2);
  lcd.setCursor(0,0);
  lcd.print("LINE 1 + ");
  lcd.setCursor(0,1);
  lcd.print("LINE 2 + ");

Code:
  lcd.clear();
  lcd.begin(16, 2);
  lcd.setCursor(0,0);
  lcd.print("LINE 1 + ", (stringdata));
  lcd.setCursor(0,1);
  lcd.print("LINE 2 + ", (stringdata));

I am missing the correct context for adding the stringdata to the same line.

Thanks, Paco
Logged

Never to old to learn and I learn every day

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 216
Posts: 13676
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


You need some simple math
Code:
  lcd.clear();
  lcd.begin(16, 2);
  lcd.setCursor(0,0);
  lcd.print("LINE 1 + ");

  lcd.setCursor(9,0);
  lcd.print(x);  // your var
  lcd.print("  ");

Homework:  do the 2nd line smiley
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

The Netherlands
Offline Offline
Sr. Member
****
Karma: 4
Posts: 331
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Rob,

Did my homework.

Code:
  lcd.clear();
  lcd.begin(16, 2);
//1st line
  lcd.setCursor(0,0);
  lcd.print("SSP ");
  lcd.setCursor(4,0);
  lcd.print(speedstartValue);
  lcd.setCursor(9,0);
  lcd.print("SPC");
  lcd.setCursor(13,0);
  lcd.print(speedcurveValue);
//2nd line
  lcd.setCursor(0,1);
  lcd.print("BK");
  lcd.setCursor(4,1);
  lcd.print(brakeValue);
  lcd.setCursor(9,1);
  lcd.print("BKC");
  lcd.setCursor(13,1);
  lcd.print(brakecurveValue);

Problem solved.
What I did not understand and could filter from other samples on the web is that you use lcd.setCursor to specify the new data on the same line.

Up to the next hurdle.

Thanks,

Paco
Logged

Never to old to learn and I learn every day

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 216
Posts: 13676
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Well done, you got an A smiley-wink

The next homework will be to only write the changing fields to the screen.
The static text does not need to be send over and over again.
The Arduino will win a lot of time that can be used for other processing.

Succes !
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

The Netherlands
Offline Offline
Sr. Member
****
Karma: 4
Posts: 331
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Did not tought of the speed of the program would suffer with that.
If you remove lcd.clear from the void loop and check if data<>olddata and take action to update the display would that be suffcient to speed up?
Or do we have to go deeper?

Bleh I hate homework.
  smiley-razz
Logged

Never to old to learn and I learn every day

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 216
Posts: 13676
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
If you remove lcd.clear from the void loop and check if data<>olddata and take action to update the display would that be suffcient to speed up?
not only remove lcd.clear but all the static strings from loop. and put these in a function for reuse...

something like this
Code:
void setup()
{
  ...
  printFixed()
}

void loop()
{
  ....
  if (digitalRead(ScreenPIN) == HIGH) printFixed(); 
  printVars();
  ...
}

void printFixed()
{
  lcd.clear();
  lcd.begin(16, 2);
  // variation
  lcd.setCursor(0,0);
  lcd.print("SSP       SPC ");
  lcd.setCursor(0,1);
  lcd.print("BK        BKC");
}


void printVars()
{
  // 1st line
  if (speedstartValue != prevSpeedstartValue)
  {
    lcd.setCursor(4,0);
    lcd.print(speedstartValue);
  }
  if (speedcurveValue != prevSpeedcurveValue)
  {
    lcd.setCursor(13,0);
    lcd.print(speedcurveValue);
  }
  etc
}


Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Central MN, USA
Offline Offline
Tesla Member
***
Karma: 73
Posts: 7189
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

If you want to completely format your output, try sprintf. Lots of times your current code will be broken. Just try to print hour:minute you will see any minute below 10 is just printed as 0-9 so 10:05 is printed as 10:5, very ugly.

Here's how to get started with sprintf to solve that type of problems and put output entirely under control:

http://liudr.wordpress.com/2012/01/16/sprintf/
Logged


Dublin, Ireland
Offline Offline
Newbie
*
Karma: 0
Posts: 34
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Also, if your LCD shared data pins with another device, for example a keypad, it will be necessary to add a small delay before printing to the LCD... correction... the delay is not necessary  smiley-red

Code:
void lcdGetPassword()
{
  delay(200);
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("   Enter Password   ");
  lcd.setCursor(0, 1);
  lcd.print("    [          ]    ");
  lcd.setCursor (5, 1);
 }
« Last Edit: April 27, 2012, 03:53:38 pm by MikeOToole » Logged

Western New York, USA
Online Online
Faraday Member
**
Karma: 36
Posts: 4304
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I wanted to understand how to the initialization process.

You can find a complete explanation of the process by following the LCD Initialization link at http://web.alfredstate.edu/weimandn.

Note:  You really should have started a new thread for this question.

Don
« Last Edit: April 09, 2012, 09:25:18 pm by floresta » Logged

Pages: [1]   Go Up
Jump to: