"Expected initializer before int" Please Help!!

Cant seem to get this code to upload in the arduino software to program the arduino uno. I was trying to make a 4 player buzzer lock out system for quizbowl or something similar. Getting all kinds of errors and correct some and now I'm left with " expected initializer before int" and "expected unqualified-Id before '{' token" if anyone can help I would greatly appreciate it.

Here is the code exactly from screen

void setup() { int S1 = 0; //switch 1 int S2 = 1; int S3 = 2; int S4 = 3; int L1 = 4; // light 1 int L2 = 5; int L3 = 6; int L4 = 7; int B = 8; //buzzer pinMode(S1, INPUT_PULLUP); pinMode(S2, INPUT_PULLUP); pinMode(S3, INPUT_PULLUP); pinMode(S4, INPUT_PULLUP); pinMode(L1, OUTPUT); // leds wired from output pin to ground } pinMode(L2, OUTPUT); pinMode(L3, OUTPUT); pinMode(L4, OUTPUT); pinMode(B, OUTPUT); // buzzer wired from output pin to ground }

}

void loop() int S1 = 0; //switch 1 int S2 = 1; int S3 = 2; int S4 = 3; int L1 = 4; // light 1 int L2 = 5; int L3 = 6; int L4 = 7; int B = 8; //buzzer {if (!digitalRead(S1)) { digitalWrite(L1,HIGH); // turn on lamp 1 digitalWrite(B,HIGH); // turn on buzzer delay(500); // wait 2 seconds digitalWrite(B,LOW); // turn off buffer delay(5000); // wait 28 more seconds digitalWrite(L1,LOW); // turn off lamp 1 } if (!digitalRead(S2)) { digitalWrite(L2,HIGH); // turn on lamp 2 digitalWrite(B,HIGH); // turn on buzzer delay(500); // wait 2 seconds digitalWrite(B,LOW); // turn off buffer delay(5000); // wait 28 more seconds digitalWrite(L2,LOW); // turn off lamp 2 } if (!digitalRead(S3)) digitalWrite(L3,HIGH); // turn on lamp 3 digitalWrite(B,HIGH); // turn on buzzer delay(500); // wait 2 seconds digitalWrite(B,LOW); // turn off buffer delay(5000); // wait 28 more seconds digitalWrite(L3,LOW); // turn off lamp 3 if (!digitalRead(S4)) digitalWrite(L4,HIGH); // turn on lamp 4 digitalWrite(B,HIGH); // turn on buzzer delay(500); // wait 2 seconds digitalWrite(B,LOW); // turn off buffer delay(5000); // wait 28 more seconds digitalWrite(L4,LOW); // turn off lamp 4 }

Hi mawoniyi

Please use code tags when posting code (the "#" button above the row of smileys).

The error message highlighted the start of loop(), I guess?

void loop()
int S1 = 0; //switch 1
int S2 = 1;
int S3 = 2;
int S4 = 3;
int L1 = 4; // light 1
int L2 = 5;
int L3 = 6;
int L4 = 7;
int B = 8; //buzzer
{if (!digitalRead(S1)) { digitalWrite(L1,HIGH); // turn on lamp 1 
etc

You need to move the variable declarations inside the "{". There may be other problems, but start by fixing this one.

EDIT

You should also use auto-format (CTRL-T) in the Arduino IDE to format the code to make it easier to understand.

And indent your "if" statements to help understand the structure of the program:

if (!digitalRead(S1)) 
{ 
    digitalWrite(L1,HIGH); // turn on lamp 1 
    etc
} // end of if statement

Regards

Ray

Thank you very much i will give it a try. I'm new to coding and this is my first project.

Hey Ray is do you think you could help rewrite the code with corrections so I could copy and paste it into the program to see if will work?

Thanks again

In the IDE put the cursor just to the right of a curly bracket or parentheses and the matching figure will be highlighted. Handy to make sure you didn’t misplace or forget a curly or paren. Putting each curly bracket on its own line help to avoid mismatch, too.

for(int n = 0; n < 10; n++)
{
    //do me 10 times
}

do you think you could help rewrite the code with corrections so I could copy and paste it into the program to see if will work?

Sorry, no. You will learn a lot more by following the advice from groundfungus and me :)

Ok thanks I'm working on it now.

Here are the updated corrections to the code. Now I'm getting even more errors. I tried to follow your instructions. Please pardon my ignorance I know it must be frustrating working with newbie. void setup() { int S1 = 0; //switch 1 int S2 = 1; int S3 = 2; int S4 = 3; int L1 = 4; // light 1 int L2 = 5; int L3 = 6; int L4 = 7; int B = 8; //buzzer pinMode(S1, INPUT_PULLUP); pinMode(S2, INPUT_PULLUP); pinMode(S3, INPUT_PULLUP); pinMode(S4, INPUT_PULLUP); pinMode(L1, OUTPUT); // leds wired from output pin to ground } pinMode(L2, OUTPUT); pinMode(L3, OUTPUT); pinMode(L4, OUTPUT); pinMode(B, OUTPUT); // buzzer wired from output pin to ground }

}

void loop() { int S1 = 0; //switch 1 int S2 = 1; int S3 = 2; int S4 = 3; int L1 = 4; // light 1 int L2 = 5; int L3 = 6; int L4 = 7; int B = 8; //buzzer if (!digitalRead(S1)) { digitalWrite(L1, HIGH); // turn on lamp 1 digitalWrite(B, HIGH); // turn on buzzer delay(500); // wait 2 seconds digitalWrite(B, LOW); // turn off buffer delay(5000); // wait 28 more seconds digitalWrite(L1, LOW); // turn off lamp 1 }// if (!digitalRead(S2)) { digitalWrite(L2, HIGH); // turn on lamp 2 digitalWrite(B, HIGH); // turn on buzzer delay(500); // wait 2 seconds digitalWrite(B, LOW); // turn off buffer delay(5000); // wait 28 more seconds digitalWrite(L2, LOW); // turn off lamp 2 } // if (!digitalRead(S3)) { digitalWrite(L3, HIGH); // turn on lamp 3 digitalWrite(B, HIGH); // turn on buzzer delay(500); // wait 2 seconds digitalWrite(B, LOW); // turn off buffer delay(5000); // wait 28 more seconds digitalWrite(L3, LOW); // turn off lamp 3 } // if (!digitalRead(S4)) { digitalWrite(L4, HIGH); // turn on lamp 4 digitalWrite(B, HIGH); // turn on buzzer delay(500); // wait 2 seconds digitalWrite(B, LOW); // turn off buffer delay(5000); // wait 28 more seconds digitalWrite(L4, LOW); // turn off lamp 4 } //

new error is expected '}' at end of input

Yeah, it doesn't get a lot more explicit than that. Please use code tags.

Why have you got two lots of variables in setup and loop?

mawoniyi: Here are the updated corrections to the code.

Put each { and } on separate lines with matching pairs indented by the same amount and the lines between them indented one extra level. You can use tools/auto format to correct the indentation for you.

Also, please use [ code ] [ /code ] tags when posting code to stop the forum software mangling it.

Ok I give up! I admit I have no clue what else to do I appreciate everyone who tried to help me with suggestions but I guess I'm too much of a Novice to understand the lingo and program language. If anyone can help rewrite the code for me so I can copy and paste it please let me know thanks.

This compiles but I don’t know if it does what you want.

int S1 = 0; //switch 1
int S2 = 1;
int S3 = 2;
int S4 = 3;
int L1 = 4; // light 1
int L2 = 5;
int L3 = 6;
int L4 = 7;
int B = 8; //buzzer

void setup()
{
  pinMode(S1, INPUT_PULLUP);
  pinMode(S2, INPUT_PULLUP);
  pinMode(S3, INPUT_PULLUP);
  pinMode(S4, INPUT_PULLUP);
  pinMode(L1, OUTPUT); // leds wired from output pin to ground }
  pinMode(L2, OUTPUT);
  pinMode(L3, OUTPUT);
  pinMode(L4, OUTPUT);
  pinMode(B, OUTPUT); // buzzer wired from output pin to ground }
}

void loop()
{
  if (!digitalRead(S1))
  {
    digitalWrite(L1, HIGH); // turn on lamp 1
    digitalWrite(B, HIGH); // turn on buzzer
    delay(500); // wait 2 seconds
    digitalWrite(B, LOW); // turn off buffer
    delay(5000); // wait 28 more seconds
    digitalWrite(L1, LOW); // turn off lamp 1
  }
  if (!digitalRead(S2))
  {
    digitalWrite(L2, HIGH); // turn on lamp 2
    digitalWrite(B, HIGH); // turn on buzzer
    delay(500); // wait 2 seconds
    digitalWrite(B, LOW); // turn off buffer
    delay(5000); // wait 28 more seconds
    digitalWrite(L2, LOW); // turn off lamp 2
  }
  if (!digitalRead(S3))
  {
    digitalWrite(L3, HIGH); // turn on lamp 3
    digitalWrite(B, HIGH); // turn on buzzer
    delay(500); // wait 2 seconds
    digitalWrite(B, LOW); // turn off buffer
    delay(5000); // wait 28 more seconds
    digitalWrite(L3, LOW); // turn off lamp 3
  }
  if (!digitalRead(S4))
  {
    digitalWrite(L4, HIGH); // turn on lamp 4
    digitalWrite(B, HIGH); // turn on buzzer
    delay(500); // wait 2 seconds
    digitalWrite(B, LOW); // turn off buffer
    delay(5000); // wait 28 more seconds
    digitalWrite(L4, LOW); // turn off lamp 4
  }
}

Thank you so much I will try it soon and let you know how it goes. Thanks again. Groundfungus

Much thanks to groundfungus everything worked now I have to attach the wires to buzzers and go from there thanks again. groundfungus!!!

You should probably not put those curly braces on the end of comments. Since they appear after the // , they will be ignored by the compiler anyway, but you are just going to confuse yourself.