In fact, it works great except the (dht_IN_Temp >= Temp_IN_Value + Temp_IN_Value_Threshold && dht_IN_Temp - dht_EXT_Temp >= 5) statement which appears not to be executed.
Is there something to do when mixing AND and OR arguments inside an IF statement ?
simkard:
In fact, it works great except the (dht_IN_Temp >= Temp_IN_Value + Temp_IN_Value_Threshold && dht_IN_Temp - dht_EXT_Temp >= 5) statement which appears not to be executed.
Is there something to do when mixing AND and OR arguments inside an IF statement ?
Sometimes the order of execution of operations is not what you might expect. I think it may be doing comparisons before addition. To force it to do what you want, try parenthesis:
Addition has higher order of precedence, so the compiler shouldn't be getting that mixed up (Operators in C and C++ - Wikipedia) - however the brackets are a good idea for clarity anyway.
or whatever. Now I'm sure you could look into the operator precedence but you shouldn't rely on that anyway. I'd be included to split the calculations from the tests
int a = Temp_IN_Value + Temp_IN_Value_Threshold;
int diff_temp = dht_IN_Temp - dht_EXT_Temp ;
int diff_hum = dht_IN_Hum - dht_EXT_Hum ;
int d = millis() - ActiveAerationPreviousStateChangeMillis ;
if(dht_IN_Temp >= a && diff_temp >= 5 || diff_hum <= -15 || d >= ActiveAerationOffDuration) {
This needs better variable names and still needs ()s to force the order of tests but I think it's a lot clearer.