I am attempting to capture the high and low temperature and humidity values, then clearing the LCD and displaying them on 2 successive screen updates. All is working correctly except that the variables for high and low are updating on every loop to the current sensor pin read after the "if" statements are run. Why is this occurring? Also note that I declare the floats for the highs and lows to the unlikely value of 10000 in order to change them all to the initial pin read on the 1st loop as I didn't find a method to determine null on the initial loop. I would appreciate any suggestions for a better method! TIA
#include <dht.h>
#include <LiquidCrystal.h>
//Low and High Temp and Humidity Variables
float lTemp=10000;
float hTemp=10000;
float lHumid=10000;
float hHumid=10000;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
dht DHT;
#define DHT11_PIN 7
void setup(){
lcd.begin(16, 2);
Serial.begin(9600);
}
void loop(){
lcd.clear();
int chk = DHT.read11(DHT11_PIN);
float CurrTemp = DHT.temperature * 1.8 + 32; //Converts celsius read from DHT read to farenheit
//Sets High and Low Temperature Readings
if (lTemp = 10000) {
lTemp = CurrTemp;
}
if (CurrTemp < lTemp) {
lTemp = CurrTemp;
}
if (hTemp = 10000) {
hTemp= CurrTemp;
}
if (CurrTemp > hTemp) {
hTemp = CurrTemp;
}
//Sets High and Low Humidity Readings
if (lHumid = 10000) {
lHumid = DHT.humidity;
}
if (DHT.humidity < lHumid) {
lHumid = DHT.humidity;
}
if (hHumid = 10000) {
hHumid = DHT.humidity;
}
if (DHT.humidity > hHumid) {
hHumid = DHT.humidity;
}
//Prints Current Temp and Humidity to LCD and Serial Monitor
lcd.setCursor(0,0);
lcd.print("Temp: ");
lcd.print(CurrTemp,1);
lcd.print((char)223);
lcd.print("F");
Serial.print(CurrTemp,1);
Serial.println(" F");
lcd.setCursor(0,1);
lcd.print("Humidity: ");
lcd.print(DHT.humidity,0);
lcd.print("%");
Serial.print("Humidity: ");
Serial.print(DHT.humidity,0);
Serial.println("%");
Serial.println("");
delay(10000);
//Prints Low and High Temp to LCD and Serial Monitor
lcd.clear();
lcd.setCursor(0,0);
lcd.print("L Temp: ");
lcd.print(lTemp,1);
lcd.print((char)223);
lcd.print("F");
Serial.print("Low Temp: ");
Serial.print(lTemp,1);
//Serial.print((char,223);
Serial.println(" F");
lcd.setCursor(0,1);
lcd.print("H Temp: ");
lcd.print(hTemp,1);
lcd.print((char)223);
lcd.print("F");
Serial.print("High Temp: ");
Serial.print(hTemp,1);
Serial.println(" F");
Serial.println("");
delay(3000);
//Prints Low and High Humidity to LCD and Serial Monitor
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Low Humid: ");
lcd.print(lHumid,0);
lcd.print("%");
Serial.print("Low Humid: ");
Serial.print(lHumid,0);
Serial.println("%");
lcd.setCursor(0,1);
lcd.print("High Humid: ");
lcd.print(hHumid,0);
lcd.print("%");
Serial.print("High Humid: ");
Serial.print(hHumid,0);
Serial.println("%");
Serial.println("");
delay(3000);
}
if (lTemp == 10000) {
setlTemp
,hTemp
,lHumid
andhHumid
... there is no need forif (hTemp == 10000) {
orif (lHumid == 10000) {
orif (hHumid == 10000) {