My LCD info is called from an IF statement but since it's clock and temperature info i don't want to just show the information but update the information constantly in real time. i don't want to use (while) loop or any other "code-blocking".
Here's the whole code:
#include <OneWire.h>
#include <LiquidCrystal_I2C.h>
#include <DS3231.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 2
int Heater= 3;
int Switch1= 4;
Time t;
LiquidCrystal_I2C lcd(0x27, 16, 2);
DS3231 rtc(SDA, SCL);
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
// Push button
boolean oldSwitchState = LOW;
boolean newSwitchState = LOW;
boolean lcdScroll = LOW;
boolean lcdBacklight = LOW;
boolean lcdWelcome = LOW;
unsigned long previousMillis = 0;
const long BacklightTime = 10000;
void setup() {
Serial.begin(115200);
pinMode(Heater, OUTPUT);
pinMode(Switch1, INPUT);
lcd.begin();
rtc.begin();
}
void loop() {
float testTemp = sensors.getTempCByIndex(0);
sensors.requestTemperatures();
t = rtc.getTime();
if(lcdWelcome == LOW){
lcd.setCursor(0,0);
lcd.print("Welcome, Admin!");
lcd.setCursor(0,1);
lcd.print("press Start");
}
// LCD
newSwitchState = digitalRead(Switch1);
if (millis() - previousMillis >= BacklightTime) {
lcd.noBacklight();
lcdBacklight = LOW;
}
else if ( lcdBacklight == LOW ){
lcd.backlight();
lcdBacklight = HIGH;
}
if ( newSwitchState != oldSwitchState ) {
if ( newSwitchState == HIGH ){
previousMillis = millis();
lcdWelcome = HIGH;
lcd.clear();
if ( lcdScroll == LOW ){
lcd.setCursor(0,0);
lcd.print(testTemp);
lcd.print(" ");
lcd.print(rtc.getTimeStr());
lcdScroll = HIGH;
}
else{
lcd.setCursor(0,0);
lcd.print(rtc.getDOWStr());
lcd.print(" ");
lcd.print(rtc.getDateStr());
lcdScroll = LOW;
}
}
oldSwitchState = newSwitchState;
}
}
How can i update the functions inside the if(lcdScroll == LOW){} and else{} statements constantly to show on display?
trueandfalseas boolean valuesif (lcdScroll == LOW){}only runs once but if i want to have the time to update in real time, time functions have to be in a loop not only run once.