Okay, so I am working on temp and relay switching. I found enough code where I was able to hack away at it and make either one work. I am sure I may need one over the other if I add more functionality, but, for the basics, is there one better than the other? Im not sure if you can tell by the snippets whats what for the best as I dont know how much more code you need to see to determine that, so, sorry in advance, just trying to save space.
Examples:
if (sensors.getTempFByIndex(1) < heater_on_temp) return heaterOn(), FansOff();
if (sensors.getTempFByIndex(1) > heater_on_temp) return heaterOff(), FansOff();
if (sensors.getTempFByIndex(1) > fan_on_temp) return FansOn(), heaterOff();
if (sensors.getTempFByIndex(1) < fan_on_temp) return FansOff(), heaterOff();
////////////////////////////////////////////////////////////////////////////
or
//////////////////////////////////////////////////////////////////////////
if (sensors.getTempFByIndex(1) <80) //Fan turns off
{
digitalWrite(fan, 0);
lcd.setCursor(16, 3);
lcd.print("Off");
}
else if (sensors.getTempFByIndex(1) >81) //Fan turns on
{
digitalWrite(fan, 1);
lcd.setCursor(16, 3);
lcd.print("On ");
}
if (sensors.getTempFByIndex(1) >76.90) //Heater turns off
{
digitalWrite(heater, 0);
lcd.setCursor(7, 3);
lcd.print("Off");
}
else if (sensors.getTempFByIndex(1) <75.90) //Heater turns on
{
digitalWrite(heater, 1);
lcd.setCursor(7, 3);
lcd.print("On ");
}
Well, if I am reading it correct, and, I know exactly .01% of C++", I would assume that "sensors.getTempFByIndex(1)" is the call to get the temp and check it to see if, < is less than the "heater_on_temp" specified in the code "int heater_on_temp = 75; //Turn on heater at this temp" which would then turn the heater on and turn the fan off.
Those lines work and the heater comes on and goes off as it should as does the fan. I was playing with both codes and they both work if I swap them out. Just wondering which one is less a hack job?
Instead of copying a bunch of code that may not be needed and posting it to the board taking up server space, I just used the snippets hoping that was enough information.
I would assume that "sensors.getTempFByIndex(1)" is the call to get the temp
Yes.
and check it to see if, < is less than the "heater_on_temp" specified in the code "int heater_on_temp = 75; //Turn on heater at this temp"
Yes.
But, what do you think that the return statement is doing? You can't return more than one value. Returning a value means that the code is in a function that expects to return a value. Why would heaterOn() return a value, if all it is doing is turning a heater (pin) on? Why would fanOff() return a value?
It's impossible to guess what the code is doing from the snippets.
CeeDee:
taking up server space, I just used the snippets hoping that was enough information.
Don't worry about server space. Post your full program.
Very many questions here turn out to have the problem in the part of the code that was not included in the snippet.
Ideally post a short complete program that illustrates the problem you are having rather than a huge program in which 95% of the stuff works correctly.