scroll a single line lcd arduino

ilie

Jul 8, 2020
1
Joined
Jul 8, 2020
Messages
1
If you want to help me, i have some questions. 
I want to scroll  just a single line of a 20x4 display. on this line i want to write a string , then a value and at least another string. The last string will be change by a condition like this


 
 
if (percent1 > 50)
{  
LCD.setCursor(0,1);
  LCD.print("Moisture S1: ");
  LCD.print(percent1); 
  LCD.print("%"); 
  LCD.print(" ");
LCD.print(" Irrigation sistem OFF");
LCD.print(" ");
}
else
{
 LCD.setCursor(0, 1);
 LCD.print("Moisture S1: ");
  LCD.print(percent1); 
  LCD.print("%"); 
 LCD.print("Irrigaion sistem ON");
 LCD.print(" ");



 
 
"Moisture S1: " / percent1 / "%"/  " Irrigaion sistem OFF" 
or 
"Moisture S1: " / percent1 / "%"/  " Irrigaion sistem ON" 
 
Thanks a lot!
 

HarryA1

Mar 4, 2009
481
Joined
Mar 4, 2009
Messages
481
Perhaps:

Code:
String DisplayString = " "; //a blank string
int percent1 = 0;
int OldPercent = 0;

void setup() 
{
  //   Serial.begin(9600); //testing
}
void loop()
{
 if( OldPercent != percent1 ) //do not scroll needlessly
 { 
   //previous string - set the cursor to second line
   LCD.setCursor(0,2);
   LCD.print(DisplayString); //moves previous line down

  if (percent1 > 50)
  {
    
   //new string 
   DisplayString = "Moisture S1 : " + String(percent1) + "%" + " Irrigaion sistem ON";
    
   //set the cursor to for new first line
   LCD.setCursor(0,1);
   LCD.print(DisplayString); //new line to top of the LCD

   OldPercent = percent1;  //set new percent
  }

  else
  {
   //new string 
   DisplayString = "Moisture S1 : " + String(percent1) + "%" + " Irrigaion sistem OFF";
    
   //set the cursor to new first line
   LCD.setCursor(0,1);
   LCD.print(DisplayString); //new line to top of the LCD

   OldPercent = percent1;  //set new percent
  }
 }

 } //end  loop
 
Last edited by a moderator:

HarryA1

Mar 4, 2009
481
Joined
Mar 4, 2009
Messages
481
or cleaner:

String DisplayString = " "; //a blank string
int percent1 = 0;
int OldPercent = 0;

void setup()
{
// Serial.begin(9600); //testing
}
void loop()
{
if( OldPercent != percent1 ) //do not scroll needlessly
{
//previous string - set the cursor to second line
LCD.setCursor(0,2);
LCD.print(DisplayString); //move previous line down

//set the cursor to for new first line
LCD.setCursor(0,1);

if (percent1 > 50)
{
//new string
DisplayString = "Moisture S1 : " + String(percent1) + "%" + " Irrigaion sistem ON";
}

else
{
//new string
DisplayString = "Moisture S1 : " + String(percent1) + "%" + " Irrigaion sistem OFF";
}
//set the cursor for new first line
LCD.setCursor(0,1);

LCD.print(DisplayString); //new line to top of the LCD
OldPercent = percent1; //set new percent
}


} //end loop


the first "set the cursor for new first line" code  is redundant; I can not see how to edit the code

 
Last edited by a moderator:
Top