Jump to content
Electronics-Lab.com Community
Sign in to follow this  
ilie

scroll a single line lcd arduino

Recommended Posts

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!

Share this post


Link to post
Share on other sites

Perhaps:

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

 

Share this post


Link to post
Share on other sites

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

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...