multiple && statements in an if causing a problem

Throw me a bone, I am new to this language. I keep getting error on too many arguments on first line in void loop

void setup() {
// put your setup code here, to run once:
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
pinMode(13, OUTPUT);

}

void loop() {
// put your main code here, to run repeatedly:
if (digitalRead(1,LOW) && if digitalRead(2,LOW) && if digitalRead(3,LOW)&& if digitalRead(4,LOW) && if digitalRead(5,LOW));
{ digitalWrite(13)== HIGH;
delay(100);
digitalWrite(12)== HIGH;
delay(100);
digitalWrite(11)== HIGH;
delay(100);
digitalWrite(10)== HIGH;
delay(100);
digitalWrite(9)== HIGH;
}
Else
{
digitalWrite(12)== LOW;
delay(100);
digitalWrite(11)== LOW;
delay(100);
digitalWrite(10)== LOW;
delay(100);
digitalWrite(9)== LOW;

Hi,
Welcome to the forum.

Please read the post at the start of any forum , entitled "How to use this Forum".
OR
http://forum.arduino.cc/index.php/topic,148850.0.html.
Then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

digitalRead(1,LOW)

What do you expect that to do?
Please read this link about "digitalRead"
https://www.arduino.cc/reference/en/language/functions/digital-io/digitalread/

https://www.arduino.cc/reference/en/language/structure/control-structure/if/

You need to read all your digital inputs and assign them to variables, THEN use the variable in your if statement.

Tom... :slight_smile:

  1. Learn to use [​code]code tags[​/code] when posting code
  2. Incorrect syntax for digitalRead
  3. Incorrect syntax for digitalWrite
  4. Incorrect syntax for "if" statement
  5. The trialling ; at the end of the if will totally mess up the logic - remove it
  6. "else" should be lower case - case is important in C/C++
  7. Missing close braces } at the end of your if and loop function
  8. Pins 0 and 1 are the serial TX and RX pins on most Arduino - pin 1 probably not the best choice

(deleted)

jonwayne1951:
Throw me a bone

okay
https://www.arduino.cc/reference/en/

Not;

 if (digitalRead(1,LOW) && if digitalRead(2,LOW)...

But this:

 if (digitalRead(1,LOW) && digitalRead(2,LOW)..

There are a number of errors that keep your code from compiling. First, each of these statements:

digitalWrite(12)== LOW;

was probably meant to be:

digitalWrite(12, LOW);

The digitalWrite() function requires two arguments: 1) the pin to write, and 2) the state (i.e., LOW or HIGH).

Also you could simplify your code a little with a function:

/*****
    Purpose: To change the state of a pin via a digital write. (Put a better description here.)

    Argument list:
       int pin               the pin to write to
       int state             the state to use

    Return value:
       void
*****/
void ChangePinState(int pin, int state)
{
   int i;

   for (i = 9; i < 14; i++) {
      digitalWrite(i, state);
   }
}

// missing code??

void loop() {

   // missing code that sets the pin??

   if (digitalRead(pin, state) == LOW) {
       ChangePinState(pin, HIGH);
   } else {
       ChangePinState(pin, LOW);
   }
}

PerryBebbington:
Not;

 if (digitalRead(1,LOW) && if digitalRead(2,LOW)...

But this:

 if (digitalRead(1,LOW) && digitalRead(2,LOW)..

Almost.

 if (digitalRead(1) == LOW && digitalRead(2) == LOW ..

It's the same for me. I can't read bad code. It totally messes up my mind.

As already said the &&s are the good bit in that statement. It's all the ifs and the digitalRead()s that are wrong.

And you have mixed up the syntax for digitalRead() and digitalWrite(). Read takes 1 argument, Write takes 2 arguments.

Steve

This style of code (even assuming it is corrected as already suggested) makes debugging almost impossible.

 if (digitalRead(1,LOW) && if digitalRead(2,LOW) && if digitalRead(3,LOW)&& if digitalRead(4,LOW) && if digitalRead(5,LOW));

I would always read the pin values into variables like this

pinAstate = digitalRead(pinA);
pinBstate = digitalRead(pinB);
pinAstate = digitalRead(pinC);
//etc

and then do the test using the values in the variables

if (pinAstate == LOW  and pinBstate == LOW and .... etc

because this allows me to print the pin values if I need to check that the IF test is working properly.

Note that I have also put the pin numbers in variables. I have just called them pinA, pinB etc but you should give them meaningful names - for example startButtonPin and startButtonPinState. That way the code becomes self documenting.

And IMHO using an ELSE clause with an IF that has 5 tests is just asking for trouble. There is one "right" answer and 31 "wrong" answers so you will have no idea what caused the failure.

...R

aarg:
It's the same for me. I can't read bad code. It totally messes up my mind.

Not everyone apparently; sometimes I skip questions with truly awful code only to later see a helpful answer from someone else who can, apparently, make sense of it.

PerryBebbington:
Not everyone apparently; sometimes I skip questions with truly awful code only to later see a helpful answer from someone else who can, apparently, make sense of it.

I get frustrated that so many people don't seem to even make the minimal effort to find their own problems by simply looking up the syntax for things like digitalWrite or even looking at example code. They just make up syntax, find out doesn't work, then all for help. You can't learn to program without putting some effort into learning.