Reading & comparing multiple digital inputs

Can anyone please guide me what mistake am I doing in below statement. My if case is misbehaving and triggers even in other cases also.

const int D0 = 2;   //pin7
const int D1 = 1;   //pin6
const int D2 = 0;   //pin5
const int D3 = 4;   //pin3
const int DISP_SV = 3;   //pin2

int STATE1, STATE2, STATE3, STATE4;

void setup()
{
  pinMode(D0, INPUT_PULLUP);
  pinMode(D1, INPUT_PULLUP);
  pinMode(D2, INPUT_PULLUP);
  pinMode(D3, INPUT_PULLUP);
  pinMode(DISP_SV, OUTPUT);
}

void loop()
{
  STATE1 = digitalRead(D0); 
  STATE2 = digitalRead(D3);
  STATE3 = digitalRead(D1);
  STATE4 = digitalRead(D2);
  if (STATE1 == LOW && STATE2 == LOW && STATE3 == HIGH && STATE4 == HIGH)
  {
    //while (STATE1 == LOW && STATE2 == LOW && STATE3 == HIGH && STATE4 == HIGH);
    bool static LED_State = 0;
    LED_State =  1^LED_State ;    // This changes state of Disp_sv.
    digitalWrite(DISP_SV, LED_State);
    delay(100);  
  }
}

Please follow the advice given in the link below when posting code. Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination

Do you have pullup resistors holding the inputs at a known state at all times or are they floating at an unknown voltage, maybe HIGH, maybe LOW ?

When debugging code with conditional statements it is often helpful to print the values being tested to see whether they look reasonable

What is the point of the #defines for the pin names ?

Which Arduino board are you using ?

Still result is same. I am using ATTiny13A with usb asp programmer.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.