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
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 frustrating for you and frustrating for us.
The people who try to help with your pro…
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.
system
Closed
January 12, 2022, 9:26am
8
This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.