16:2 lcd messages: whats the issue with my code?

So i have two messages on the lcd working fine. When i try to add a third message it does not appear to display.

I have attached the full code below but here are the relevant lines.

these are declared before setup:

//set the delay between the LCD display setting using millis (not the delay function)
unsigned long switchMillis = 0;
unsigned long interval = 5000; //5 seconds for each lcd screen
byte count = 0;

boolean firstScreenFlag = false;
boolean secondScreenFlag = false;
boolean thirdScreenFlag = false;

in setup the interior light function:

//  turn on interior lights at dusk and turn off after door shuts

void doCoopInteriorLightDusk() {

  if ((unsigned long)(millis() - lastTwilightTime) > TwilightDelay) {     // delay 5 mins

    lastTwilightTime = millis();


    doReadPhotoCell();
    bottomSwitchPinVal = digitalRead(bottomSwitchPin);
    if (bottomSwitchPinVal == 1) {                          // if bottom reed switch circuit is open (door is open)
      if (photocellReading  >= 200) {                        // if it's twilight
        if (photocellReading <= 350) {
          digitalWrite (relayInteriorLedStrip, LOW);          // turn on interior light relay
          if (SerialDisplay) {
            //Serial.println(" Interior Light: On");
          }
        }
      }
    }
    else if (bottomSwitchPinVal == 0) {                    // if bottom reed switch circuit is closed (door is closed)
      digitalWrite (relayInteriorLedStrip, HIGH);              // turn off interior light relay
      if (SerialDisplay) {
        //Serial.println(" Interior Light: Off");
      }
    }
  }
}

the lcd message functions:

//  lcd screen displays
void doLcdMsg1() {

  float temperature = getTemp();                 // create temperature variable

  pinMode(backLight, OUTPUT);            // backlight pin set as output
  digitalWrite(backLight, HIGH);         // backlight on
  lcd.begin(16, 2);                      // columns, rows
  lcd.clear();                           // start with blank screen
  lcd.setCursor(0, 0);                   // set cursor to column 0, row 0
  lcd.print("Coop Temp:");               // show "Temp"
  lcd.print (temperature) ;              // show temperature of interior coop
  lcd.print("C");                        // show "C"
  lcd.setCursor(0, 1);                   // set cursor to column 0, row 1
  lcd.print("Coop Door:");               // show "Coop Door"

  if (bottomSwitchPinVal == 0) {         // if coop door bottom switch is closed
    lcd.print("Closed");                 // display "Closed"
  }
  else  {
    lcd.print("Open");            // if coop door bottom switch is open display "Open"

  }
}

void doLcdMsg2() {

  lcd.clear();                            // clear the screen

  if (digitalRead(relayFan) == LOW) {                //relayFan set to LOW as Songle Relay is on with Gnd Voltage
    lcd.print("Cooling Fan: ON");
  }                                     //display that Cooling fan is on or off
  else {
    lcd.print("Cooling Fan: OFF");
  }

  lcd.setCursor(0, 1);

  if (digitalRead(relayHeat) == LOW) {               //relayHeater set to LOW as Songle Relay is on with Gnd Voltage
    lcd.print("Coop Heater: ON");
  }                                     //display that Cooling fan is on or off
  else {
    lcd.print("Coop Heater: OFF");
  }
}
void doLcdMsg3() {

  lcd.clear();                            // clear the screen

  if (digitalRead(relayInteriorLedStrip) == HIGH) {
    lcd.print("Lighting : OFF");
  }                                     //display if interior lighting is on or off
  else {
    lcd.print("Lighting : ON");
  }

  lcd.setCursor(0, 1);
  lcd.print("Happy Chickens");         //display the happy message

}

and finally the loop:

void loop() {

  doReadPhotoCell();
  doCoopHVAC();
  doCoopDoor();
  doCoopDoorLed();
  doCoopInteriorLightDusk();

  // Delays for the LCD screen messages

  if (millis() - switchMillis > interval) 
  {
    count++;

    if (count == 1)
      firstScreenFlag = true;

    if (count == 2)
    {
      secondScreenFlag = true;
      count = 0;
    }
    if (count == 3)
    {
      thirdScreenFlag = true;
      count = 0;
    }
    switchMillis += interval; //millis();
  }

  if (firstScreenFlag)
  {
    doLcdMsg1();
    firstScreenFlag = false;
  }

  if (secondScreenFlag)
  {
    doLcdMsg2();
    secondScreenFlag = false;
  }
  
if (thirdScreenFlag)
  {
    doLcdMsg3();
    thirdScreenFlag = false;
  }
}

the first two messages display fine but doLcdMsg3(); doesn't display at all?

can anyone tell me why?

chicken_coop_auto.ino.ino (19.4 KB)

You should be initializing your lcd in the setup() function.
void setup(void)
{
// existing stuff

pinMode(backLight, OUTPUT); // backlight pin set as output
digitalWrite(backLight, HIGH); // backlight on
lcd.begin(16, 2); // columns, rows
}

and not calling it in the doMsg1() function

also, when count == 2, you set it back to 0 if the if() block so it probably never gets to 3.
if (count == 2)
{
secondScreenFlag = true;
count = 0;
}

also, when count == 2, you set it back to 0 if the if() block so it probably never gets to 3.
    if (count == 2)
    {
      secondScreenFlag = true;
      count = 0;

talk about staring me in the face!!!

Thanks for that..

I don't mean to be picky, but names like doLcdMsg1(), doReadPhotoCell(), doCoopHVAC(), doCoopDoor(), doCoopDoorLed(), and doCoopInteriorLightDusk() tellus NOTHING about what the functions are for. Every good function name consists of verbs and nouns that describe EXACTLY what a function does. Do, as the verb, doesn't mean squat.

Read is a perfectly good verb. readPhotoCell() is a good name. doRead... is a crappy name.

What, exactly, does do coop door LED do? One can't even guess.

What, exactly, does do coop door LED do? One can't even guess.

A wild guess. It changes the state of an LED on a chicken coop door.

UKHeliBob:
A wild guess. It changes the state of an LED on a chicken coop door.

Does changeLEDStateOnCoopDoor() require guessing?

Is programming about guessing? Or is it about dealing with facts?

I was not suggesting that the function name was ideal or even acceptable, but I was challenging your assertion that

One can't even guess.

I agree that you should not need to guess.

Paul you must be screwed when the NIKE adverts run!

I'm sure there are easier to read names that describe each function and i agree the ones used aren't the best. I'll take it onboard and may well change them as you suggest.

I'm still learning and these pointers are helpful thanks.

edit:

i've changed the names to:

readThePhotoCell();
  controlCoopTemp();
  controlTheDoor();
  controlTheDoorLed();
  controltheInteriorLights();
 displayLcdMessageOne();
displayLcdMessageTwo();
    displayLcdMessageThree();

these indeed read better.
Alex