Simple code but lost logic.

Hi Guys.
I do need some clarification why this statement wont work. Simply, if i press LowerPessed button and non of the 4 outputs are flagged as active i want all of them to be high. But they are not.

 if (( lowerPressed == 1 ) && (frontLeftEnable == 0 && frontRightEnable == 0 && rearLeftEnable == 0 && rearRightEnable == 0))  {
      digitalWrite(fldown, HIGH);
      digitalWrite(frdown, HIGH);
      digitalWrite(rldown, HIGH);
      digitalWrite(rrdown, HIGH);
    }
    else
    {
      digitalWrite(fldown, LOW);
      digitalWrite(frdown, LOW);
      digitalWrite(rldown, LOW);
      digitalWrite(rrdown, LOW);
    }

However, in this scenatio where i`m actually choosing side manually with the same lowerPressed button everything works just fine.

  if ((lowerPressed == 1) && (frontLeftEnable == 1)) {
    digitalWrite(fldown, HIGH);
  }
  else
  {
    digitalWrite(fldown, LOW);
  }

  if ((lowerPressed == 1) && (frontRightEnable == 1)) {
    digitalWrite(frdown, HIGH);
  }
  else
  {
    digitalWrite(frdown, LOW);
  }

  if ((lowerPressed == 1) && (rearLeftEnable == 1)) {
    digitalWrite(rldown, HIGH);
  }
  else
  {
    digitalWrite(rldown, LOW);
  }
  if ((lowerPressed == 1) && (rearRightEnable == 1)) {
    digitalWrite(rrdown, HIGH);
  }
  else
  {
    digitalWrite(rrdown, LOW);
  }

Why? :smiley:

Thanks for any help

If the snippet doesn't work as you expect, the problem could be in how you wired the switches, or in the code you didn't post. You've left far too much out of your post to get any help.

Ah got it

Both statements cannot be together.
This works fine

void Lower(void) {
 if (( lowerPressed == 1 ) && (frontLeftEnable == 0 && frontRightEnable == 0 && rearLeftEnable == 0 && rearRightEnable == 0))  {
      digitalWrite(fldown, HIGH);
      digitalWrite(frdown, HIGH);
      digitalWrite(rldown, HIGH);
      digitalWrite(rrdown, HIGH);
    }
    else
    {
      digitalWrite(fldown, LOW);
      digitalWrite(frdown, LOW);
      digitalWrite(rldown, LOW);
      digitalWrite(rrdown, LOW);
    }
  if ((lowerPressed == 1) && (frontLeftEnable == 1)) {
    digitalWrite(fldown, HIGH);
  }
  else
  {
   // digitalWrite(fldown, LOW);
  }

  if ((lowerPressed == 1) && (frontRightEnable == 1)) {
    digitalWrite(frdown, HIGH);
  }
  else
  {
   // digitalWrite(frdown, LOW);
  }

  if ((lowerPressed == 1) && (rearLeftEnable == 1)) {
    digitalWrite(rldown, HIGH);
  }
  else
  {
   // digitalWrite(rldown, LOW);
  }
  if ((lowerPressed == 1) && (rearRightEnable == 1)) {
    digitalWrite(rrdown, HIGH);
  }
  else
  {
  //  digitalWrite(rrdown, LOW);
  }



}

((lowerPressed == 1) && (frontLeftEnable == 0))

((lowerPressed == 1) && (frontLeftEnable == 1))