My code is simple; I'm not sure why my lcd loops through all the screens I have setup as toggle options. It should display each screen individually based upon what button is pressed. (right or left) Can anyone see my problem and help me fix it? It may be obvious, so I apologize for my newbieness.. I removed most of the code due to the limited amount of characters aloud in a post, but if requested, i can post the whole thing. My problem should be in the following code:
void setup()
{
lcd.begin(16, 2);
lcd.clear();
lcd.setCursor(0, 0);
dht.begin();
sensors.begin();
}
int sensorReadDelay=1000;
int lastSensorRead=0;
float h;
float t;
float insideTempC;
float outsideTempC;
float waterTankTempC;
float temp;
float wata;
float owside;
void loop() {
currentButton = keypad.getKey();//Read Button Press
if(currentButton > 0){
checkButtons();
}
if(millis()-lastSensorRead>sensorReadDelay){ //millis() gets the time
/*Everthing inbetween these curly braces should only be run every 1 second*/
readSensors();
/*These two pieces of code can also go in here
so the won't have to be run as many times*/
if(temp >= setTemp) //Trip relay if temp is exceeded for DHT22 SENSOR
{
digitalWrite(CHANNEL1, LOW);
} else {
digitalWrite(CHANNEL1, HIGH);
}
if (wata >= waterSetTemp) {
digitalWrite(CHANNEL3, HIGH);
//digitalWrite(CHANNEL2, HIGH);
} else {
digitalWrite(CHANNEL3, LOW);
}
/*Save off the time the sensors were read so we don't read them again until 1 second is past*/
lastSensorRead=millis();
}
float h = dht.readHumidity();
float t = dht.readTemperature();
float insideTempC = sensors.getTempC(inside);
float outsideTempC = sensors.getTempC(outside);
float waterTankTempC = sensors.getTempC(waterTank);
float temp = (t * 1.8) + 32; //Convert *C to *F.
float wata = (insideTempC * 1.8) + 32; //Convert *C to *F.
float owside = (outsideTempC * 1.8) + 32; //Convert *C to *F.
if (displayTemp == 1) //Shows DHT22 SENSOR temp screen upon first boot
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("ROOM ");
lcd.print(int(temp));
lcd.print("");
lcd.print((char)223); // degree symbol
lcd.print("F");
lcd.setCursor(0,1);
lcd.print("SET TEMP ");
lcd.print(setTemp);
lcd.print("");
lcd.print((char)223);
lcd.print("F");
currentDisplay = 0;
}
if (displayHumid == 1)// DHT22 SENSOR
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("HUMIDITY ");
lcd.print(int(h));
lcd.print(" %");
lcd.setCursor(0,1);
lcd.print("SET HUMID ");
lcd.print(setHumid);
lcd.print(" %");
currentDisplay = 1;
}
if (waterDisplay == 1)
{
sensors.requestTemperatures(); //This command must be there in order to get live stream of temperature data
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Water ");
printTemperature(inside);
lcd.print("");
lcd.print((char)223); // degree symbol
//lcd.print("F");
lcd.setCursor(0,1);
lcd.print("SET TEMP ");
lcd.print(waterSetTemp);
lcd.print("");
lcd.print((char)223);
//lcd.print("F");
currentDisplay = 2;
}
if ( sensorsDisplay == 1)
{
sensors.requestTemperatures();
lcd.clear();
lcd.setCursor(0,0);
lcd.print(" ");
printTemperature(inside);
lcd.print("");
lcd.print((char)223); // degree symbol
lcd.print("F");
lcd.setCursor(0,1);
lcd.print(" ");
printTemperature(outside);
lcd.print("");
lcd.print((char)223); // degree symbol
lcd.print("F");
currentDisplay = 3;
}
} // LEAVE THIS ONE HERE FOR LOOP COMPLETION
void checkButtons(){
//MENU SYSTEM
// Reads which buttons are pressed.
// No button = 0
// Select button = 1
// Left button = 2
// Up Button = 3
// Down Button = 4
// Right Button = 5
if (currentButton == 5 && currentDisplay == 0)//Turns display temp off so it will show humidity after pressing right button
{
displayHumid = 1;
displayTemp = 0;
waterDisplay = 0;
sensorsDisplay = 0;
updateScreen();
}
if (currentButton == 5 && currentDisplay == 1) //Inside Water Display
{
waterDisplay = 1;
sensorsDisplay = 0;
displayHumid = 0;
displayTemp = 0;
updateScreen();
}
if (currentButton == 5 && currentDisplay == 2)
{
sensorsDisplay = 1;
displayTemp = 0;
waterDisplay = 0;
displayHumid = 0;
updateScreen();
}
if (currentButton == 5 && currentDisplay == 3)
{
displayTemp = 1;
waterDisplay = 0;
displayHumid = 0;
sensorsDisplay = 0;
updateScreen();
}
// Left Button Reverse Scrolling Through Menu
if (currentButton == 2 && currentDisplay == 0)
{
waterDisplay = 1;
sensorsDisplay = 0;
displayHumid = 0;
displayTemp = 0;
updateScreen();
}
if (currentButton == 2 && currentDisplay == 1)
{
displayTemp = 1;
waterDisplay = 0;
sensorsDisplay = 0;
displayHumid = 0;
updateScreen();
}
if (currentButton == 2 && currentDisplay == 2)
{
displayHumid = 1;
displayTemp = 0;
waterDisplay = 0;
sensorsDisplay = 0;
updateScreen();
}
if (currentButton == 2 && currentDisplay == 3)
{
sensorsDisplay = 1;
displayHumid = 0;
displayTemp = 0;
waterDisplay = 0;
updateScreen();
}
if (currentButton == 3 && currentDisplay == 0) //When up button is pressed and the temp screen is showing, increment the set temp
{
++setTemp;
updateScreen();
}
if (currentButton == 4 && currentDisplay == 0) //When down button is pressed with the temp screen showing, decrement set temp
{
--setTemp;
updateScreen();
}
if (currentButton == 3 && currentDisplay == 1) //When up button is pressed and the humidity screen is showing, inc the set humidity
{
++setHumid;
updateScreen();
}
if (currentButton == 4 && currentDisplay == 1) //When down button is pressed and humidity screen is showing, dec the set humidity
{
--setHumid;
updateScreen();
}
if (waterDisplay == 1 && currentButton == 3)
{
++waterSetTemp;
updateScreen();
}
if (waterDisplay == 1 && currentButton == 4)
{
--waterSetTemp;
updateScreen();
}
}
void updateScreen(){
if (displayTemp == 1) //Shows DHT22 SENSOR temp screen upon first boot
{
delay (5000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("ROOM ");
lcd.print(int(temp));
lcd.print("");
lcd.print((char)223); // degree symbol
lcd.print("F");
lcd.setCursor(0,1);
lcd.print("SET TEMP ");
lcd.print(setTemp);
lcd.print("");
lcd.print((char)223);
lcd.print("F");
currentDisplay = 0;
}
if (displayHumid == 1)// DHT22 SENSOR
{
delay (5000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("HUMIDITY ");
lcd.print(int(h));
lcd.print(" %");
lcd.setCursor(0,1);
lcd.print("SET HUMID ");
lcd.print(setHumid);
lcd.print(" %");
currentDisplay = 1;
}
if (waterDisplay == 1)
{
delay (5000);
sensors.requestTemperatures(); //This command must be there in order to get live stream of temperature data
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Water ");
printTemperature(inside);
lcd.print("");
lcd.print((char)223); // degree symbol
lcd.setCursor(0,1);
lcd.print("SET TEMP ");
lcd.print(waterSetTemp);
lcd.print("");
lcd.print((char)223);
currentDisplay = 2;
}
if ( sensorsDisplay == 1)
{
sensors.requestTemperatures();
lcd.clear();
lcd.setCursor(0,0);
lcd.print(" ");
printTemperature(inside);
lcd.print("");
lcd.print((char)223); // degree symbol
lcd.print("F");
lcd.setCursor(0,1);
lcd.print(" ");
printTemperature(outside);
lcd.print("");
lcd.print((char)223); // degree symbol
lcd.print("F");
currentDisplay = 3;
}