# Reading & comparing multiple digital inputs

**URL:** <https://forum.arduino.cc/t/reading-comparing-multiple-digital-inputs/905273>\
**Category:** Programming\
**Created:** [September 14, 2021, 8:28am UTC](https://forum.arduino.cc/t/reading-comparing-multiple-digital-inputs/905273 "2021-09-14T08:28:04Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mishras1132](https://avatars.discourse-cdn.com/v4/letter/m/ba8739/32.png) [@mishras1132](https://forum.arduino.cc/u/mishras1132)\
**Post date:** [September 14, 2021, 8:28am UTC](https://forum.arduino.cc/t/reading-comparing-multiple-digital-inputs/905273/1 "2021-09-14T08:28:04Z")

</div>

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.

```cpp
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);  
  }
}

```

---

<div class="post-metadata">

**Author:** ![UKHeliBob](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ukhelibob/32/215663_2.png) [@UKHeliBob](https://forum.arduino.cc/u/UKHeliBob)\
**Post date:** [September 14, 2021, 8:34am UTC](https://forum.arduino.cc/t/reading-comparing-multiple-digital-inputs/905273/2 "2021-09-14T08:34:45Z")

</div>

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

> [@How to get the best out of this forum](https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum/679966):
>
> See also [FAQ - Arduino Forum](https://forum.arduino.cc/faq) for general rules on forum behaviour and etiquette. Hello, Welcome to the Arduino Forum. This guide explains how to get the best out of this forum. Please read and follow the instructions below. Being new here you might think this is having rules for the sake of rules, but that is not the case. If you don’t follow the guidelines all that happens is there is a long exchange of posts while we try to get you to tell us what we need in order to help you, which is fru…

---

<div class="post-metadata">

**Author:** ![UKHeliBob](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ukhelibob/32/215663_2.png) [@UKHeliBob](https://forum.arduino.cc/u/UKHeliBob)\
**Post date:** [September 14, 2021, 8:39am UTC](https://forum.arduino.cc/t/reading-comparing-multiple-digital-inputs/905273/3 "2021-09-14T08:39:30Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![mishras1132](https://avatars.discourse-cdn.com/v4/letter/m/ba8739/32.png) [@mishras1132](https://forum.arduino.cc/u/mishras1132)\
**Post date:** [September 14, 2021, 9:26am UTC](https://forum.arduino.cc/t/reading-comparing-multiple-digital-inputs/905273/7 "2021-09-14T09:26:07Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [January 12, 2022, 9:26am UTC](https://forum.arduino.cc/t/reading-comparing-multiple-digital-inputs/905273/8 "2022-01-12T09:26:42Z")

</div>

Closed on January 12, 2022, 9:26am UTC

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