Hi all, I'm quite new to programming but have limited knowledge which i have been puting to use.
I'm printing to LCD four values. two on the first screen, then delaying for 5 seconds before printing the two further values.
Initially i used the delay function, but as i got further through the code, it became apparent that the delay function was not the way forward as it also delayed other parts of the code from being implemented.
I have read up on using millis instead, however it doesn't seem to be working for me.
//this is declared outside setup and loop
//set the delay between the LCD display setting using millis (not the delay function)
unsigned long lcdTimeOn = 0;
unsigned long lcdTimeOff = 5000;
//declared inside setup
// lcd
void doLcdMsg() {
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"
}
if ((unsigned long)(millis() - lcdTimeOn) > lcdTimeOff) { // delay 5 seconds
lcdTimeOn = millis();
}
lcd.clear(); // clear the screen
if (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 (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");
}
if ((unsigned long)(millis() - lcdTimeOn) > lcdTimeOff) { // delay 5 seconds
lcdTimeOn = millis();
}
when i upload the above code the LCD just show " Coop Heater: Off" and below that Cooling Fan: Off and does not cycle through to show "Coop Temp" or Coop Door.
If i remove the code from after:
else {lcd.print("Open"); // if coop door bottom switch is open display "Open"
}
Then i get my first LCD display done correctly, so i know the issue is around the delay using millis.
Any help would be appreciated as i've come off night shifts and my head is aching!
Thanks Alex