and compile again and do (add) what the compiler is expecting BEFORE Serial
(rinse and ) repeat - compile again and do what compiler is again expecting BEFORE Serial
All better. It compiled and barring other errors elsewhere it will run.
And next time type in
if()
only at first and THAN insert ( type into brackets field) the compound condition inside the brackets.
Now you can check your logic by inserting values
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
int temperature, humidity;
temperature = 79;
humidity = 14;
// if (temperature < 80) || (temperature > 112 && ( humidity < 13) replaced with
correct if goes here
Serial.print("TRUE");
Serial.print("FALSE");
}
void loop()
{
}
PS Read up on how compound statement is evaluated - direction , precedence etc.
Have fun.
if (temperature >= 80 && temperature <= 112 && humidity <= 13)
{
// do stuff here if true
}
This is a if statement.
An else if would be if this isnt true and something else is
Thank you , it works !
I spent some hours trying to get it working, finally I thought, time to ask the gurus. That was exactly what I was trying to accomplish: "only if the WHOLE expression is true, do this"
Here is the peace of code I was working on, I need to double check the correction "adj", but that is not a problem:
I added an screen shot. The top row is a sensor in my master bedroom, the bottom row is a sensor outside in the backyard.
The numbers represent the following: temperature , humidity, heat index, and dew point.
So nice to see how the humidity is inversely proportional to temperature.
// HEAT INDEX
double HIH6130::computeHeatIndex_F(void) {
double adj = ((13-humidity)/4)*sq((17-abs(temperature_F-95.))/17);
Thank you so much for your tips. I tested but did not set the else statement to a particular value to see if the correct decision was made. What I mean is, I did not heat up the sensor to see if the program followed the correct logic.
Unless you have the operator precedences memorized (and why the hell would you), adding parentheses makes sure that the compiler interprets the statement the way that you want.
This tests that the temperature is between 80 and 112 (inclusive). Only if that condition is satisfied will the humidity be checked. Only when the temperature is in range AND the humidity is low will the body of the statement be executed.
techalex:
Thank you so much for your tips. I tested but did not set the else statement to a particular value to see if the correct decision was made. What I mean is, I did not heat up the sensor to see if the program followed the correct logic.
I have to apology for my omission - I did not specifically included the "else" also.
I believe the issue was incorrect syntax of "if" compound condition , not how "if" construct works.