Can't get the splash screen to clear

Hi Forum,
this is my first post, so be merciful ....... :slight_smile:

A brief description of the project I'm working on:
With 2 pushbuttons (UP and DOWN) I can scroll between 4 different screens, each one of them showing a different message on the LCD, and activating at the same time a dedicated digital output.
This is the part that is working fine.

What I would like to implement (and I'm struggling with) is a splash screen, that should show some text on the LCD for few seconds after the board is powered up.
I can't get it working, for some (unknown to me) mistakes in the code, the splash screen message is not clearing after the timer is up, but it gets "partially overlapped" with the text of the next screen.
I've commented out the offending lines in the attached code, could you guys please have a look at it and let me know?
thanks
G

#include <LiquidCrystal.h>

LiquidCrystal lcd(2, 3, 4, 5, 6, 7); //To lcd (RS,E,D4,D5,D6,D7)

#define LED1 13 //   OUTPUT   1
#define LED2 12 //   OUTPUT   2
#define LED3 11 //   OUTPUT   3
#define LED4 9 //   OUTPUT   4

//Counter to change positions of pages

int page_counter=1 ;       //To move beetwen pages


//-------Pins-----//
int up = 8;               //Up button
int down = 10;           //Down button
//---------Storage debounce function-----//
boolean current_up = LOW;          
boolean last_up=LOW;            
boolean last_down = LOW;
boolean current_down = LOW;
        

void setup() {
  lcd.begin(16,2); 
pinMode(LED1, OUTPUT);  
pinMode(LED2, OUTPUT);  
pinMode(LED3, OUTPUT);  
pinMode(LED4, OUTPUT);   

}

   //---- De-bouncing function for all buttons----//
boolean debounce(boolean last, int pin)
{
boolean current = digitalRead(pin);
if (last != current)
{
delay(100); // DEBOUNCE DELAY BUTTON  
current = digitalRead(pin);
}
return current;
}

// BEGINNING OF OFFENDING CODE

     //SPLASH SCREEN AT STARTUP
   // lcd.setCursor(0,0);
    //lcd.print("       splash");
    //lcd.setCursor(0,1);
    //lcd.print(" screen");
    //delay(5000);
    //lcd.clear();
// END OF OFFENDING CODE

void loop() {

 
      
    
current_up = debounce(last_up, up);         //Debounce for Up button
current_down = debounce(last_down, down);   //Debounce for Down button

//----Page counter function to move pages----//

//Page Up
    if (last_up== LOW && current_up == HIGH){  //When up button is pressed
      lcd.clear();                     //When page is changed, lcd clear to print new page  
      if(page_counter <4){              //Page counter never higher than 3(total of pages)
      page_counter= page_counter +1;   //Page up
      
      }
      else{
      page_counter= 4;  
      }
  }
  
    last_up = current_up;

//Page Down
    if (last_down== LOW && current_down == HIGH){ //When down button is pressed
      lcd.clear();                     //When page is changed, lcd clear to print new page    
      if(page_counter >1){              //Page counter never lower than 1 (total of pages)
      page_counter= page_counter -1;   //Page down
      
      }
      else{
      page_counter= 1;  
      }
  }
    
    last_down = current_down;

    if(page_counter == 1){
      digitalWrite(LED1, HIGH); //on out 1
      }
      else { 
      digitalWrite(LED1, LOW); //off out  1
} 

     if(page_counter == 2){
      digitalWrite(LED2, HIGH); //on out 2
      }
      else { 
      digitalWrite(LED2, LOW); //off out 2
} 

      if(page_counter == 3){
      digitalWrite(LED3, HIGH); //  on out 3
      }
      else { 
      digitalWrite(LED3, LOW); //off out 3
} 

if(page_counter == 4){
      digitalWrite(LED4, HIGH); // on out 4
      }
      else { 
      digitalWrite(LED4, LOW); // off out 4
} 


//------- Switch function ---// 
  switch (page_counter) {
   
    case 1:{     //screen 1
      lcd.setCursor(0,0);
      lcd.print("screen");
      lcd.setCursor(0,1);
      lcd.print(" 1 ");
      
      
    }
    break;

    case 2: { //screen 2
     lcd.setCursor(0,0);
     lcd.print(" screen");
     lcd.setCursor(0,1);
     lcd.print(" 2 ");
    }
    break;

    case 3: {   //screen 3
     lcd.setCursor(0,0);
     lcd.print(" screen");
     lcd.setCursor(0,1);
     lcd.print(" 3 ");
    }
    break;

     case 4:{     //screen 4
      lcd.setCursor(0,0);
      lcd.print(" screen");
      lcd.setCursor(0,1);
      lcd.print(" 4 ");
    }
    break;
    
  }       //switch end
  
}         //loop end

Put the code at the end of the setup() function. If that doesn't work, post your code again exactly as you've compiled and uploaded it, no changes please as we need to see the code that doesn't work, not code you've changed after the fact.

Fred,
I appreciate your help.
Here we go, this is the latest and greatest, see line at the end of the SPLASH SCREEN sequence, if I try to compile it I'm getting an "lcd does not name a type" message:

#include <LiquidCrystal.h>

LiquidCrystal lcd(2, 3, 4, 5, 6, 7); //To lcd (RS,E,D4,D5,D6,D7)

#define LED1 13 //   OUTPUT   1
#define LED2 12 //   OUTPUT   2
#define LED3 11 //   OUTPUT   3
#define LED4 9 //   OUTPUT   4

//Counter to change positions of pages

int page_counter=1 ;       //To move beetwen pages


//-------Pins-----//
int up = 8;               //Up button
int down = 10;           //Down button
//---------Storage debounce function-----//
boolean current_up = LOW;          
boolean last_up=LOW;            
boolean last_down = LOW;
boolean current_down = LOW;
        

void setup() {
  lcd.begin(16,2); 
pinMode(LED1, OUTPUT);  
pinMode(LED2, OUTPUT);  
pinMode(LED3, OUTPUT);  
pinMode(LED4, OUTPUT);   

}

   //---- De-bouncing function for all buttons----//
boolean debounce(boolean last, int pin)
{
boolean current = digitalRead(pin);
if (last != current)
{
delay(100); // DEBOUNCE DELAY BUTTON  
current = digitalRead(pin);
}
return current;
}


     //SPLASH SCREEN AT STARTUP
    lcd.setCursor(0,0);
    lcd.print("       splash");
    lcd.setCursor(0,1);
    lcd.print(" screen");
    delay(5000);
     lcd.clear(); // NOTE if I try to compile I get an "lcd does not name a type" message on this line
    


void loop() {

 
      
    
current_up = debounce(last_up, up);         //Debounce for Up button
current_down = debounce(last_down, down);   //Debounce for Down button

//----Page counter function to move pages----//

//Page Up
    if (last_up== LOW && current_up == HIGH){  //When up button is pressed
      lcd.clear();                     //When page is changed, lcd clear to print new page  
      if(page_counter <4){              //Page counter never higher than 3(total of pages)
      page_counter= page_counter +1;   //Page up
      
      }
      else{
      page_counter= 4;  
      }
  }
  
    last_up = current_up;

//Page Down
    if (last_down== LOW && current_down == HIGH){ //When down button is pressed
      lcd.clear();                     //When page is changed, lcd clear to print new page    
      if(page_counter >1){              //Page counter never lower than 1 (total of pages)
      page_counter= page_counter -1;   //Page down
      
      }
      else{
      page_counter= 1;  
      }
  }
    
    last_down = current_down;

    if(page_counter == 1){
      digitalWrite(LED1, HIGH); //on out 1
      }
      else { 
      digitalWrite(LED1, LOW); //off out  1
} 

     if(page_counter == 2){
      digitalWrite(LED2, HIGH); //on out 2
      }
      else { 
      digitalWrite(LED2, LOW); //off out 2
} 

      if(page_counter == 3){
      digitalWrite(LED3, HIGH); //  on out 3
      }
      else { 
      digitalWrite(LED3, LOW); //off out 3
} 

if(page_counter == 4){
      digitalWrite(LED4, HIGH); // on out 4
      }
      else { 
      digitalWrite(LED4, LOW); // off out 4
} 


//------- Switch function ---// 
  switch (page_counter) {
   
    case 1:{     //screen 1
      lcd.setCursor(0,0);
      lcd.print("screen");
      lcd.setCursor(0,1);
      lcd.print(" 1 ");
      
      
    }
    break;

    case 2: { //screen 2
     lcd.setCursor(0,0);
     lcd.print(" screen");
     lcd.setCursor(0,1);
     lcd.print(" 2 ");
    }
    break;

    case 3: {   //screen 3
     lcd.setCursor(0,0);
     lcd.print(" screen");
     lcd.setCursor(0,1);
     lcd.print(" 3 ");
    }
    break;

     case 4:{     //screen 4
      lcd.setCursor(0,0);
      lcd.print(" screen");
      lcd.setCursor(0,1);
      lcd.print(" 4 ");
    }
    break;
    
  }       //switch end
  
}         //loop end

"At the end of setup()" means inside setup().

The Arduino IDE can format your code. e.g.

#include <LiquidCrystal.h>

LiquidCrystal lcd(2, 3, 4, 5, 6, 7); //To lcd (RS,E,D4,D5,D6,D7)

#define LED1 13 //   OUTPUT   1
#define LED2 12 //   OUTPUT   2
#define LED3 11 //   OUTPUT   3
#define LED4 9 //   OUTPUT   4

//Counter to change positions of pages

int page_counter = 1 ;     //To move beetwen pages


//-------Pins-----//
int up = 8;               //Up button
int down = 10;           //Down button
//---------Storage debounce function-----//
boolean current_up = LOW;
boolean last_up = LOW;
boolean last_down = LOW;
boolean current_down = LOW;


void setup() {
    lcd.begin(16, 2);
    pinMode(LED1, OUTPUT);
    pinMode(LED2, OUTPUT);
    pinMode(LED3, OUTPUT);
    pinMode(LED4, OUTPUT);

}

//---- De-bouncing function for all buttons----//
boolean debounce(boolean last, int pin)
{
    boolean current = digitalRead(pin);
    if (last != current)
    {
        delay(100); // DEBOUNCE DELAY BUTTON
        current = digitalRead(pin);
    }
    return current;
}


//SPLASH SCREEN AT STARTUP
lcd.setCursor(0, 0);
lcd.print("       splash");
lcd.setCursor(0, 1);
lcd.print(" screen");
delay(5000);
lcd.clear(); // NOTE if I try to compile I get an "lcd does not name a type" message on this line



void loop() {




    current_up = debounce(last_up, up);         //Debounce for Up button
    current_down = debounce(last_down, down);   //Debounce for Down button

    //----Page counter function to move pages----//

    //Page Up
    if (last_up == LOW && current_up == HIGH) { //When up button is pressed
        lcd.clear();                     //When page is changed, lcd clear to print new page
        if (page_counter < 4) {           //Page counter never higher than 3(total of pages)
            page_counter = page_counter + 1; //Page up

        }
        else {
            page_counter = 4;
        }
    }

    last_up = current_up;

    //Page Down
    if (last_down == LOW && current_down == HIGH) { //When down button is pressed
        lcd.clear();                     //When page is changed, lcd clear to print new page
        if (page_counter > 1) {           //Page counter never lower than 1 (total of pages)
            page_counter = page_counter - 1; //Page down

        }
        else {
            page_counter = 1;
        }
    }

    last_down = current_down;

    if (page_counter == 1) {
        digitalWrite(LED1, HIGH); //on out 1
    }
    else {
        digitalWrite(LED1, LOW); //off out  1
    }

    if (page_counter == 2) {
        digitalWrite(LED2, HIGH); //on out 2
    }
    else {
        digitalWrite(LED2, LOW); //off out 2
    }

    if (page_counter == 3) {
        digitalWrite(LED3, HIGH); //  on out 3
    }
    else {
        digitalWrite(LED3, LOW); //off out 3
    }

    if (page_counter == 4) {
        digitalWrite(LED4, HIGH); // on out 4
    }
    else {
        digitalWrite(LED4, LOW); // off out 4
    }


    //------- Switch function ---//
    switch (page_counter) {

        case 1: {    //screen 1
                lcd.setCursor(0, 0);
                lcd.print("screen");
                lcd.setCursor(0, 1);
                lcd.print(" 1 ");


            }
            break;

        case 2: { //screen 2
                lcd.setCursor(0, 0);
                lcd.print(" screen");
                lcd.setCursor(0, 1);
                lcd.print(" 2 ");
            }
            break;

        case 3: {   //screen 3
                lcd.setCursor(0, 0);
                lcd.print(" screen");
                lcd.setCursor(0, 1);
                lcd.print(" 3 ");
            }
            break;

        case 4: {    //screen 4
                lcd.setCursor(0, 0);
                lcd.print(" screen");
                lcd.setCursor(0, 1);
                lcd.print(" 4 ");
            }
            break;

    }       //switch end

}         //loop end

This shows exactly where you go wrong. And it cost me one finger press.
I configure the IDE for 4 spaces instead of TAB. I find this feature worth its weight in gold.
Admittedly, I have a "better" Code Beautifier but ctl-T does a pretty good job.

David.

.....working now, my mistake was to keep the splash screen sequence outside the curly brackets in the setup :o :o

thanks guys