Hello to all.
Im currently creating and writing code for my spa controller. At this stage most of the code is working fine however under one sub routine my push button fails to work when its pressed again.
Currently the code acts as follows when testing:
- if (potVal > temp) - both button controls work ie Can turn on and off when ever.
2. if (potVal < temp) - this is the issue once temperature set is below the current temperature the Heat pushbutton code will not switch to off when pushed, however the pump pushbutton will switch the mode to off - if (temp > overTemp) - both button controls work ie Can turn on and off.
Ive been going over the code for many days, and a fresh pair of eyes/comments would be greatly appreciated.
I hope ive explained it enough for you all to understand my issue
my code in part. if you need the whole thing just ask
void loop()
{
digitalWrite(RELAY1, relayState1); //define relay1 as global
digitalWrite(RELAY2, relayState2); //define relay2 as global
buttonState1 = digitalRead(buttonPin1); // read the state of the pushbutton value:
buttonState2 = digitalRead(buttonPin2); // read the state of the pushbutton value:
// Heat BUTTON check if the pushbutton is pressed. if it is, the buttonState is HIGH:
if (buttonState1 == HIGH && previousState1 == LOW && millis() - time1 > debounce)
{
if (relayState1 == HIGH) // Go to Heat Mode:
{
opState = HEAT; // start Heat control
}
else
{
opState = OFF; // turn off control
}
time1 = millis();
previousState1 == buttonState1;
}
// Filter BUTTON check if the pushbutton is pressed. if it is, the buttonState is HIGH:
if (buttonState2 == HIGH && previousState2 == LOW && millis() - time2 > debounce)
{
if (relayState2 == HIGH) // Go to Filter mode:
{
opState = AUTO; // start filter control
}
else
{
opState = OFF; // turn off control
}
time2 = millis();
previousState2 == buttonState2;
}
// thermistor Coding
double temp;
temp = Thermistor(analogRead(ThermistorPIN));
//Temp LCD data
lcd.setCursor(0, 3);
lcd.print("Temperature");
lcd.setCursor(12, 3);
lcd.print(temp);
lcd.setCursor(17, 3);
lcd.print((char)223);
lcd.print("C");
//LCD STATIC DATA
lcd.setCursor(0, 0);
lcd.print("Operating Mode:");
lcd.setCursor(0, 1);
lcd.print("Set Temp To:");
lcd.setCursor(14, 1);
lcd.print((char)223);
lcd.print("C");
lcd.setCursor(0, 2);
lcd.print("PUMP:");
lcd.setCursor(10, 2);
lcd.print("HEATER:");
switch (opState)
{
case OFF:
off();
delay(100);
break;
case HEAT:
setTemp();
delay(100);
break;
case AUTO:
filter();
delay(100);
break;
}
}
void off()
{
relayState2 = HIGH; //pump off
relayState1 = HIGH; // heater off
lcd.setCursor(15, 0);
lcd.print(" ");
lcd.setCursor(15, 0);
lcd.print("OFF");
lcd.setCursor(12, 1);
lcd.print("00");
lcd.setCursor(5, 2);
lcd.print(" ");//clear
lcd.setCursor(5, 2);
lcd.print("OFF");//PUMP OFF
lcd.setCursor(17, 2);
lcd.print(" ");//clear
lcd.setCursor(17, 2);
lcd.print("OFF");//HEATER OFF
}
void setTemp()
{
lcd.setCursor(15, 0);
lcd.print(" ");
lcd.setCursor(15, 0);
lcd.print("HEAT");
int overTemp = 35; //over ride temp
//Pot coding
sensorValue = analogRead(potPin); // read analog in value
outputValue = map(sensorValue, 0, 1022.90, 0.0, 35.9); // map it to the range of the analog out
potVal = outputValue;
// thermistor Coding
double temp;
temp = Thermistor(analogRead(ThermistorPIN));
// POT LCD data
lcd.setCursor(12, 1);
lcd.print(" ");
lcd.setCursor(12, 1);
lcd.print(potVal);
delay(100);
if (potVal > temp)
{
lcd.setCursor(12, 1);
lcd.print(" ");
lcd.setCursor(12, 1);
lcd.print(potVal);
relayState2 = LOW; //pump on
relayState1 = LOW; //heater on
lcd.setCursor(5, 2);
lcd.print(" ");//clear
lcd.setCursor(5, 2);
lcd.print("ON");//PUMP ON
lcd.setCursor(17, 2);
lcd.print(" ");//clear
lcd.setCursor(17, 2);
lcd.print("ON");//HEATER ON
}
if (potVal < temp)
{
relayState2 == LOW;
lcd.setCursor(12, 1);
lcd.print(" ");
lcd.setCursor(12, 1);
lcd.print(potVal);
relayState2 = LOW; //pump on
relayState1 = HIGH; // heater off
lcd.setCursor(5, 2);
lcd.print(" ");//clear
lcd.setCursor(5, 2);
lcd.print("ON");//PUMP ON
lcd.setCursor(17, 2);
lcd.print(" ");//clear
lcd.setCursor(17, 2);
lcd.print("OFF");//HEATER OFF
}
if (temp > overTemp)
{
lcd.setCursor(12, 1);
lcd.print(" ");
lcd.setCursor(12, 1);
lcd.print(potVal);
relayState2 = HIGH; //pump off
relayState1 = HIGH; //heater off
lcd.setCursor(5, 2);
lcd.print(" ");//clear
lcd.setCursor(5, 2);
lcd.print("OFF");//PUMP OFF
lcd.setCursor(17, 2);
lcd.print(" ");//clear
lcd.setCursor(17, 2);
lcd.print("OFF");//HEATER OFF
}
}