20x4 LCD "scrolling" question

With my current project always expanding to add new features to my reef controller i'm running out of room on my display to show all the info.On my first line I have time and LED intensity for blue n white,second line are temps from 2 temp sensors,3rd line is the pH and ORP sensor and last line shows what relays are on.

Am looking to add a salinity monitor,ato and doser info and was wondering how to take two of my lines to switch every 30 seconds between the info of pH,OPR n temps with salinity,ATO and doser and vice versa.Could someone point me in the right direction please.

check the following snippet:

#define DISPLAYTIMEOUT 1000   // every second next screen
unsigned long lastDisplay = 0;

int screenID = 0;

void loop()        
{
  // DO MEASUREMENTS
  ...

  // DO ACTIONS
  ...

  // DO DISPLAY
  if (millis() - lastDisplay > DISPLAYTIMEOUT )   
  {
    lastDisplay = millis();
    doDisplay()
   }

  // OTHER
  ...
}


void doDisplay()
{
  screenID = constrain(screenID, 0, 2);
  switch(screenID)
  {
    case 0 : Lcd.print("this is screen 0");  // add your favo print statement here :)
      break;
    case 1 : Lcd.print("this is screen 1");
      break;
    case 2 : Lcd.print("this is screen 2");
      break;
    default: // should not happen => reset screenID
      screenID = 0;
      break;
  }
  screenID++;
}

Hopes this helps

Thanks alot Rob.... $)

So I just ran the “test sketch” and it stays at “this is screen 2” and doesn’t go back to the beginning to loop…am I doing something wrong?

#include <LiquidCrystal.h>
#include <Wire.h>                 // Comunication I2C 
#define DS1307_I2C_ADDRESS 0x68 //set rtc
#define DISPLAYTIMEOUT 1000   // every second next screen
unsigned long lastDisplay = 0;

int screenID = 0;

LiquidCrystal lcd(22,23,24,25,26,27);


/*|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||  R T C   C L O C K   D S 1 3 0 7  |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/



byte decToBcd(byte val)    // Convert normal decimal numbers to binary coded decimal
{
  return ( (val/10*16) + (val%10) );
}


byte bcdToDec(byte val)    // Convert binary coded decimal to normal decimal numbers
{
  return ( (val/16*10) + (val%16) );
}

// 1) Sets the date and time on the ds1307
// 2) Starts the clock
// 3) Sets hour mode to 24 hour clock
// Assumes you're passing in valid numbers
void setDateDs1307(byte second, // 0-59
byte minute, // 0-59
byte hour, // 1-23
byte dayOfWeek, // 1-7
byte dayOfMonth, // 1-28/29/30/31
byte month, // 1-12
byte year) // 0-99
{
  Wire.beginTransmission(DS1307_I2C_ADDRESS);
  Wire.send(0);
  Wire.send(decToBcd(second)); // 0 to bit 7 starts the clock
  Wire.send(decToBcd(minute));
  Wire.send(decToBcd(hour));   // If you want 12 hour am/pm you need to set
  // bit 6 (also need to change readDateDs1307)
  Wire.send(decToBcd(dayOfWeek));
  Wire.send(decToBcd(dayOfMonth));
  Wire.send(decToBcd(month));
  Wire.send(decToBcd(year));
  Wire.endTransmission();
}

// Gets the date and time from the ds1307
void getDateDs1307(byte *second,
byte *minute,
byte *hour,
byte *dayOfWeek,
byte *dayOfMonth,
byte *month,
byte *year)
{
  // Reset the register pointer
  Wire.beginTransmission(DS1307_I2C_ADDRESS);
  Wire.send(0);
  Wire.endTransmission();

  Wire.requestFrom(DS1307_I2C_ADDRESS, 7);

  // A few of these need masks because certain bits are control bits
  *second = bcdToDec(Wire.receive() & 0x7f);
  *minute = bcdToDec(Wire.receive());
  *hour = bcdToDec(Wire.receive() & 0x3f); // Need to change this if 12 hour am/pm
  *dayOfWeek = bcdToDec(Wire.receive());
  *dayOfMonth = bcdToDec(Wire.receive());
  *month = bcdToDec(Wire.receive());
  *year = bcdToDec(Wire.receive());
}

/*|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||  D E F I N E  :  O N E S E C O N D |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/



void onesecond() //function that runs once per second while program is running
{
  byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
  getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);
  lcd.setCursor(0, 0);
  if(hour>0)
  {
    if(hour<=12)
    {
      lcd.print(hour, DEC);
    }
    else
    {
      lcd.print(hour-12, DEC);
    }
  }
  else
  {
    lcd.print("12");
  }
  lcd.print(":");
  if (minute < 10) {
    lcd.print("0");
  }
  lcd.print(minute, DEC);
  //lcd.print(":");
  //if (second < 10) {
  //  lcd.print("0");
  //}
  //lcd.print(second, DEC);
  if(hour<12)
  {
    lcd.print("AM");
  }
  else
  {
    lcd.print("PM");
  }
  lcd.print(" ");
  delay(1000);
}



void doDisplay()
{
  screenID = constrain(screenID, 0, 2);
  switch(screenID)
  {
    case 0 : lcd.setCursor(0, 1);
    lcd.print("this is screen 0");  // add your favo print statement here :)
      break;
    case 1 : lcd.setCursor(0, 1);
    lcd.print("this is screen 1");
      break;
    case 2 : lcd.setCursor(0, 1);
    lcd.print("this is screen 2");
      break;
    default: // should not happen => reset screenID
      screenID = 0;
      break;
  }
  screenID++;
}

void setup(){
    Wire.begin();
    lcd.begin(20, 4); // set up the LCD's number of rows and columns:
   // Print a message to the LCD.
}

void loop()        
{
    onesecond();
      byte second, minute, hour, dayOfWeek, dayOfMonth, month, year; //declare variables to hold the times
  
  getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year); //read the RTC times

  if (millis() - lastDisplay > DISPLAYTIMEOUT )   
  {
    lastDisplay = millis();
    doDisplay();
   }

}
void doDisplay()
{
  screenID = constrain(screenID, 0, 2);  // prevents out of range values
  switch(screenID)
  {
    case 0 : lcd.setCursor(0, 1);
    lcd.print("this is screen 0");  // add your favo print statement here :)
      break;
    case 1 : lcd.setCursor(0, 1);
    lcd.print("this is screen 1");
      break;
    case 2 : lcd.setCursor(0, 1);
    lcd.print("this is screen 2");
      break;
    default: // should not happen => reset screenID
      screenID = 0;
      break;
  }
  screenID++;    // sert next screen 
  if (screenID > 2) screenID = 0;  //  wrap around if all screens done       <<<<<<<<<<<<<<<<<<<<<<<<<< missing line , sorry
}

got it working now.....so is there a way to clear each line before the new line is displayed without part of the info being displayed from the previous line.

You have to look that up in the LCD specs/datasheet. often there is a specific command. You allways can print a string of spaces to a line to clear it.

Or better fill the line up with spaces after the text:

char buffer[16];  // 16 is LCD line size => should be a #define
strcpy(buffer, "text to display");
int l = strlen(buffer);

for (int i=l; i< 15; i++)  buffer[i] = ' ';  // fill up with spaces util last pos -1

buffer[15] = '\0';  // terminate string correctly

lcd.setCursor(0,1);
lcd.print(buffer);