Go Down

Topic: LCD 2 Line messages + extra data (Read 1 time) previous topic - next topic

backbone

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: [Select]
  lcd.clear();
  lcd.begin(16, 2);
  lcd.setCursor(0,0);
  lcd.print("LINE 1 + ");
  lcd.setCursor(0,1);
  lcd.print("LINE 2 + ");


Code: [Select]
  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
Never to old to learn and I learn every day

robtillaart


You need some simple math
Code: [Select]

  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 :)
Rob Tillaart

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

backbone

Rob,

Did my homework.

Code: [Select]
  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
Never to old to learn and I learn every day

robtillaart

Well done, you got an A ;)

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 !
Rob Tillaart

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

backbone

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.
  :P
Never to old to learn and I learn every day

robtillaart

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: [Select]

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
}



Rob Tillaart

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

liudr

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/

MikeOToole

#7
Apr 03, 2012, 11:00 pm Last Edit: Apr 27, 2012, 10:53 pm by MikeOToole Reason: 1
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: [Select]
void lcdGetPassword()
{
 delay(200);
 lcd.clear();
 lcd.setCursor(0, 0);
 lcd.print("   Enter Password   ");
 lcd.setCursor(0, 1);
 lcd.print("    [          ]    ");
 lcd.setCursor (5, 1);
}

floresta

#8
Apr 10, 2012, 04:23 am Last Edit: Apr 10, 2012, 04:25 am by floresta Reason: 1
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

Go Up