Go Down

Topic: How to clear "extra" characters on Liquid Crystal ? (Read 73 times) previous topic - next topic


I am hoping someone has solved this problem previously, or can identify what I am doing wrong. I want to display a data field and a text field on one row of a 1602 lcd. I can do that, BUT...for displaying a motor rpm, that will vary the number of digits from 3 to 4 digits...when the data increases from 3 to 4 digits, the text shifts over 1 column, then when the data reduces from 4 to 3 digits, I've got a leftover text character...so, remove the text...then when the data reduces from 4 to 3 digits, I've got a leftover data digit.  Photo panel 1 shows the display with 4 data digits and 'rpm' text. Photo panel 2 shows 3 data digits and 'rpmm' text. How do I clear that. I've looked through the lcd library without success. And obviously lcd.clear doesn't work in void loop as you will never see anything on the lcd. Thanks to respondents.

Here is the pertinent part of the sketch:
void setup() {
  lcd.begin(16,2); // set the lcd display to 16 columns and 2 rows
  pinMode (pulsePin,OUTPUT);
  pinMode (pulseResistor,INPUT); 
  delay(2500); // set a delay before the 'ignition' loop starts

void loop() {
  float pulseFactor = analogRead(pulseResistor); // needs to be 'float' or won't work correctly
  pulse(); // call subroutine
  // because pulseTimeLo=100ms-10ms(HI pulse)-15ms(LOW pulse) 
  int rpm=2400-1800*(pulseFactor/1023);
  lcd.print(" rpm");


OK...photo now attached...I hope


If you don't care about the text jumping around and moving left & right just print additional spaces after the m in "rpm"

Code: [Select]

lcd.print(" rpm    ");

but if you want the text "rpm" to stay in a fixed position and right adjust the number then you will have to either print extra spaces or zeros when the number is smaller before you print "rpm".

Code: [Select]

if(rpm < 1000)
if(rpm < 100)
if(rpm < 10)
lcd.print(" rpm");

Alternatively you could use sprintf and let it do all the formatting for the entire line:
Code: [Select]
char buf[16];
sprintf(buf, "%04d rpm", rpm)

--- bill


Thanks very much for the tips. Yeah, not too much concerned if the text jumps around as long as it's what it should be. A few ideas to play with...again, thanks. John

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131