If statement confusion?

i dont understand why it does both if statements even tho I change the input value?

// C++ code
//
void setup()
{
  pinMode(12, OUTPUT);
  pinMode(A0, INPUT);
  Serial.begin(9600);
}

void loop()
{
  if (digitalRead(A0 == LOW));
  {
  	Serial.print("ape");
    digitalWrite(12, HIGH);
    delay(1000); // Wait for 1000 millisecond(s)
    digitalWrite(12, LOW);
    delay(1000); // Wait for 1000 millisecond(s)
  }
  if (digitalRead(A0) == HIGH);
  {
  	Serial.print("drage");
    digitalWrite(12, HIGH);
    delay(1000); // Wait for 1000 millisecond(s)
    digitalWrite(12, LOW);
    delay(1000); // Wait for 1000 millisecond(s)
  }
}

Post a schematic.

Post a project image.

if (digitalRead(A0 == LOW));

That's nonsense. Did you mean

if (digitalRead(A0) == LOW)

and

if (digitalRead(A0) == HIGH)

A review might be in order.

1 Like

delete ; ´s

2 Likes

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