In function 'void loop()': 17:6: error: expected ';' before 'digitalWrite' 23:5: error: expected ';' before 'digitalWrite' exit status 1

void setup() {
// put your setup code here, to run once:
pinMode(13,INPUT);
pinMode(3,OUTPUT);

}

void loop() {
int x;
int i=3;
x=digitalRead(13);
i=i+x;
if(i%2==0)
{ if(digitalRead(13)==0)
digitalWrite(3,HIGH);
else (digitalRead(13)==1)
digitalWrite(3,HIGH);
}
else if(i%2==1)
{ if(digitalRead(13)==0)
digitalWrite(3,LOW);
else(digitalRead(13)==1)
digitalWrite(3,LOW);
}
}

Hi, @achilies018
Welcome to the forum.
To add code please click this link;

What model Arduino are you using?

You need to check ALL your else if... statements, they need { and } .
https://www.arduino.cc/en/pmwiki.php?n=Reference/Else

Tom... :smiley: :+1: :coffee: :australia:
PS, Tip, Before compiling your code in the IDE hit < CTRL > < T >, it will automatically format your code and let you see where your brackets are in the code.

Not quite true but definitely advisable :wink:

An else does not use a condition.

Hi,

if(i%2==0)
{ if(digitalRead(13)==0)
digitalWrite(3,HIGH);
else (digitalRead(13)==1)
digitalWrite(3,HIGH);
}

An if.. and few { and } missing there.

@achilies018 what era you trying to do with your code?

Tom.... :smiley: :+1: :coffee: :australia:

i think you intended

    if (i%2==0)
    {
        if (digitalRead (13)==0)
            digitalWrite (3,HIGH);
        else if (digitalRead (13)==1)
            digitalWrite (3,HIGH);
    }

but if the if condition is NOT true, the else is the NOT cond

    if (i%2==0)
    {
        if (digitalRead (13)==0)
            digitalWrite (3,HIGH);
        else
            digitalWrite (3,HIGH);
    }

but looks like both the if and else do the same thing, so you probably intended

    if (i%2==0)
    {
        if (digitalRead (13)==0)
            digitalWrite (3,HIGH);
        else
            digitalWrite (3,LOW);
    }

but this could simple be

    if (i%2==0)
        digitalWrite (3, ! digitalRead (13));
1 Like

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