Summer/winter switch code check please

Hi can someone confirm if this snippet of code is correct please. I am trying to assign different values to an integer dependant on the state of a digital input (High or low) for a summer/ winter switch on an irrigation project. The bit I am not sure of is using the comma to separate the two statements
(Min = 70, Max = 73).

void loop() {

  if (sum_win = HIGH){
    (Min = 70, Max = 73);}
    else if (sum_win = LOW){
      (Min =50, Max = 55);
    }

The code compiles ok but Im not sure if the way I have written it will do what I am expecting it to.
Thanks

No, it probably doesn’t. This alone will sink it:

if (sum_win = HIGH){

because you have used the assignment operator instead of a comparison operator there.

…and the commas are terrible form.

  if (sum_win == HIGH)
  {
   Min = 70;
   Max = 73;
  }
    else
  {
   Min = 50;
   Max = 55;
  }

would be 100% more readable, and the else if is redundant.

I also agree with reply #2 about your naming convention. Min and Max are also terrible names, they don’t say the min or max of what.

Hi can someone confirm if this snippet of code is correct please.

I can confirm that it is NOT.

 if (sum_win = HIGH)

It makes no sense to assign HIGH to sum_win.
The name sum_win is dumb. It is summer or it isn't.

bool summer = true;
if(coldAsAWitchesTit)
   summer = false;

if(summer)
{
   // man it's hot...
}

makes a lot more sense to me.

   (Min = 70, Max = 73);

Abusing the comma operator is rarely a good idea.
(The) (parentheses) (are) (useless).

Hi

Thanks for the pointers the sum_win was a short hand way of summer/winter ( as I want differnt miniumum / maximum paramiters for the respective seasons Not just a true/false ( i.e. switch closed and 5 volts present Min has a value of 70 or switch open and zero volts present Min has a value of 50), I didnt use a Slash as I thought it would read it as a division.

Yeah, the point was that you can't deduce the logic state from the name. If I say, "it is summer/winter", you don't know which, but if I say, "it is summer" or "it is winter", you do.

I get your point, cheers

but if I say, "it is summer" or "it is winter", you do.

Or if I say is it is not summer, you can easily deduce that it must be winter.

PaulS:
Or if I say is it is not summer, you can easily deduce that it must be winter.

Reminds me of my time in Manchuria. :slight_smile:

PaulS:
Or if I say is it is not summer, you can easily deduce that it must be winter.

Yes. I'd like to offer to one of my favorite forms of boolean statements:

bool summer = !coldAsAWitchesTit;

I just love how these read.

Cheers,
/dev

/dev:

bool summer = !coldAsAWitchesTit;

If the attribute 'Witches' implies the temperature of the bosom, wouldn't that be an all-season effect? :wink: