Hi all, just wanted some feedback on this piece of code, i am trying to controll some heatpads, and the moment any of them drop below a certian temperature, i want them all to activate, i tinkered some with if or statements, but i couldnt get it to function the way i wanted. ill show you my attempt, and my solution, if you know how to make it simpler, let me know!
Attempt:
if ((Tc1>30)||(Tc2>30)||(Tc3>30)) {
digitalWrite(Heatpads, LOW);
Serial.println("Heatpads are now off!");
}
else {
digitalWrite(Heatpads, HIGH);
Serial.println("Heatpads are now on!");
}
delay(2000);
solution:
if (Tc1<30){
digitalWrite(Heatpads,HIGH);
Serial.print("Sensor 1 to low, heatpads on!");
}
else if (Tc2<30){
digitalWrite(Heatpads,HIGH);
Serial.print("Sensor 2 to low, heatpads on!");
}
else if(Tc3<30){
digitalWrite(Heatpads,HIGH);
Serial.print("Sensor 3 to low, heatpads on!");
}
else{
digitalWrite(Heatpads,LOW);
Serial.println("Temps are ok, heatpads are off!");
}
delay(5000);
if ((Tc1<30)||(Tc2<30)||(Tc3<30)) {
digitalWrite(Heatpads, HIGH);
Serial.println("Heatpads are now on!");
}
else {
digitalWrite(Heatpads, LOW);
Serial.println("Heatpads are now OFF!");
}
though it woundt be necessary since its only a snippet of the full code, guess i was wrong, my bad, ill try to follow this advice the next time i post any code
The problem with only posting snippets of code is that they cannot be seen in context. For instance, what is data type of the variables, are the variables local or global or even both as is sometimes the case, etc