Output Problems

Hello. Noob here. Here is my code:

int gillyPin1 = 6;
int gillyPin2 = 7;
int ledPin = 8;
void setup() {
  // put your setup code here, to run once:
 pinMode(gillyPin1,INPUT);
 pinMode(gillyPin2,INPUT);
 pinMode(ledPin,OUTPUT);
digitalWrite(ledPin,LOW);
Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
 if(digitalRead(gillyPin1 = HIGH) or digitalRead(gillyPin2 = HIGH))  {
  digitalWrite(ledPin,HIGH);
  Serial.println("Out!");
 }
 else {
  digitalWrite(ledPin,0);
 }
 delay(500);
}

For you it may be self explanatory. I am trying to output "Out!" whenever gillyPin1 or gillyPin2 goes high. However I always get high in the serial monitor even if none of the pins is high. I know my Arduino has no problems. But why this?

Look very carefully at your first (and only) "if"

if(digitalRead(gillyPin1 = HIGH) or digitalRead(gillyPin2 = HIGH))

The above is wrong!

Also, how are the switches wired?

Use == for if test, as = is used for allocation of a variable.

Also, although what you do is correct, you should get used to using HIGH and LOW instead of 1 and 0 for digitalWrites

  digitalWrite(ledPin,LOW);

Your if statement has additional problems:

Original:

if(digitalRead(gillyPin1 = HIGH) or digitalRead(gillyPin2 = HIGH))

the = will assign the value HIGH to gillyPin1 and gillyPin2, with HIGH being equal to 1, so effectively you have written:

if (digitalRead(1) or digitalRead(1))

if you change the = to ==, then you will be evaluating the expression (gillyPin1 == HIGH), which will return true, because gillyPin1 is 6, and any number other than 0 is considered to be HIGH. Same for gillyPin2. True is defined as 1, so again you have:

if (digitalRead(gillyPin1 == HIGH) or digitalRead(gillyPin2 == HIGH))

being equivalent to

if (digitalRead(1) or digitalRead(1))

You want to read the input, then compare it to HIGH, such as:

if ((digitalRead(gillyPin1) == HIGH) or (digitalRead(gillyPin2) == HIGH))

I'm a bit surprised it works, but the normal symbol for or is || , and the statement is usually written as:

if ((digitalRead(gillyPin1) == HIGH) || (digitalRead(gillyPin2) == HIGH))

if ((digitalRead(gillyPin1) == HIGH) || (digitalRead(gillyPin2) == HIGH))

Note that since HIGH and true are both defined to be 1 you can use:

if (digitalRead(gillyPin1) || digitalRead(gillyPin2))  // If either is HIGH

If you want to test for 0/false/LOW you can use the logical inversion operator: '!'

if (!digitalRead(gillyPin1) || !digitalRead(gillyPin2)) // If either is LOW