I want to put a 2 seconds delay to temperature reading but the millis()
delay is not applying.
#include <OneWire.h>
#include <LiquidCrystal_I2C.h>
#include <DS3231.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 2
Time t;
LiquidCrystal_I2C lcd(0x27, 16, 2);
DS3231 rtc(SDA, SCL);
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
const int OnHour = 23;
const int OnMin = 42;
const int checkTemp = 2000;
const int checkTempinterval = 0;
void setup() {
Serial.begin(115200);
pinMode(3, OUTPUT);
lcd.begin();
lcd.backlight();
rtc.begin();
}
void loop() {
t = rtc.getTime();
float testTemp;
testTemp = temperature();
lcd.setCursor(0,0);
lcd.print(testTemp);
lcd.print(" ");
lcd.print(rtc.getTimeStr());
lcd.setCursor(0,1);
lcd.print(rtc.getDOWStr());
lcd.print(" ");
lcd.print(rtc.getDateStr());
if(testTemp >= 28){
digitalWrite(3,HIGH);
}else{
digitalWrite(3,LOW);
}
// if(t.hour == OnHour && t.min == OnMin){
// digitalWrite(3,HIGH);
// }else{
// digitalWrite(3,LOW);
// }
}
float temperature(){
unsigned long currenttime = millis();
if(currenttime - checkTempinterval >= checkTemp){
sensors.requestTemperatures();
float testTemp = sensors.getTempCByIndex(0);
currenttime = checkTempinterval;
return testTemp;
}
}
currenttime = checkTempinterval;
, it's pointless as it won't exist anymore after the return.