Answer the question
In order to leave comments, you need to log in
How to regulate the temperature within the given limits?
In my code, the first condition is executed only for the first time for some reason, although for me the logic is correct, by default ktemp = false
Code:
if (ktemp = false && temp_atmosphere < t1) {
digitalWrite(heatPin, HIGH); //включение обогревателя
digitalWrite(airPin, HIGH); //включение вентилятора
ktemp = true;
Serial.println("obogrev BKJI");
}
else if (ktemp = true && temp_atmosphere < (t1 + 0.5)) {
digitalWrite(heatPin, HIGH); //включение обогревателя
digitalWrite(airPin, HIGH); //включение вентилятора
}
else if (temp_atmosphere > (t1 + 3) || hum_atmosphere > 85) { //если темепература на 3с или влажность выше 85%
digitalWrite(heatPin, LOW); //выключение обогревателя
digitalWrite(airPin, HIGH); //включение вентилятора
Serial.println("obduv BKJI");
}
else {
ktemp = false;
digitalWrite(heatPin, LOW); //выключение обогревателя
digitalWrite(airPin, LOW); //выключение вентилятора
Serial.println("BCE BbIK");
}
Answer the question
In order to leave comments, you need to log in
:[|||||||||||||||||||||||||/////////////////-many more kilometers button accordion-\\\\\\\\\\\\\\|]:
I assume you want to test ktemp for falsehood.
In this case, you need to write two equal signs, because one sign in C++ is an assignment.
Better yet, write:if ( (!ktemp) && (temp_atmosphere < t1) ) {
I see a strange thing: ktemp is set to true only after the heater is turned on, but the second condition checks that ktemp = true and turns the heater on again. But I don't think it's relevant to the problem.
The else branch will work only if the heating is on, and the temperature is between t1 + 0.5 - t1 + 3. I suspect that the system flies this interval very quickly and the else if (temp_atmosphere > (t1 + 3) branch begins, in which ktemp is not reset. Explain , by the way, purpose of ktemp - not absolutely understood what for it.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question