ilie Posted July 8, 2020 Report Share Posted July 8, 2020 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! Quote Link to comment Share on other sites More sharing options...
HarryA Posted July 8, 2020 Report Share Posted July 8, 2020 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 Quote Link to comment Share on other sites More sharing options...
HarryA Posted July 9, 2020 Report Share Posted July 9, 2020 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.