Help Please

I would really appreciate help with this program. This is supposed to be a traffic light where the normal cycle continues and when i press a button, pedestrians can cross. I have and error of an unqualified id before } . Can someone help me please.

int run;
int red1 = 10;
int yellow = 9;
int green1 = 8;
int buttonPin = 12;
int red2 = 6;
int green2 = 7;

void setup()
{
run = 0;
buttonPin = 12;
pinMode(red1, OUTPUT);
pinMode(yellow, OUTPUT);
pinMode(green1, OUTPUT);
pinMode(red2, OUTPUT);
pinMode(green2, OUTPUT);
digitalWrite(green1, HIGH);
digitalWrite(red2, HIGH);
pinMode(buttonPin, INPUT_PULLUP);
}

void loop(){
changeLights();
delay(15000);}

void changeLights(){

digitalWrite(green1, LOW);
digitalWrite(yellow, HIGH);
digitalWrite(red2, HIGH);
delay(3000);

digitalWrite(yellow, LOW);
digitalWrite(red1, HIGH);
digitalWrite(green2, HIGH);
delay(5000);

digitalWrite(red2, HIGH);
digitalWrite(green2, LOW);
delay(750);

digitalWrite(green1, HIGH);
}
{
if(digitalRead(buttonPin) == LOW)
{
if(run == 0)
{
run = 255;
}
else
{
run = 0;
}

if(run > 0)

void loop() {
if (digitalRead(button) == HIGH){
delay(15); // software debounce
if (digitalRead(button) == HIGH) {
// if the switch is HIGH, ie. pushed down - change the lights!
changeLights();
}
}
}

void changeLights(){
// green off, yellow on for 3 seconds
digitalWrite(green1, LOW);
digitalWrite(yellow, HIGH);
delay(3000);

// turn off yellow, then turn red on for 5 seconds
digitalWrite(yellow, LOW);
digitalWrite(red1, HIGH);
delay(1000);

digitalWrite(red2, LOW);
digitalWrite(green2, HIGH);

delay(5000);
// turn off red and yellow, then turn on green
digitalWrite(green2, LOW);

digitalWrite(red2, HIGH);
delay(500);

digitalWrite(red1, LOW);
digitalWrite(green1, HIGH);
}
}
}

Use CTRL T to format the sketch.
Please use code tags.
Use the </> icon in the posting menu.

[code] Paste sketch here. [/code]

You have only one loop() in a sketch.

You have several errors in that code besides the one you mentioned. See the comments in the code. Some of the errors would be obvious if you use the autoformat tool (crtl-t or Tools, Autoformat). You can have only one loop() function and the changeLights() function is duplicated, also illegal. You need to be careful to make sure the brackets are in matched pairs. In the IDE, if you put the cursor to the right of a bracket, the matching bracket will be highlighted.

int run;
int red1 = 10;
int yellow = 9;
int green1 = 8;
int buttonPin = 12;
int red2 = 6;
int green2 = 7;

void setup()
{
  run = 0;
  buttonPin = 12;
  pinMode(red1, OUTPUT);
  pinMode(yellow, OUTPUT);
  pinMode(green1, OUTPUT);
  pinMode(red2, OUTPUT);
  pinMode(green2, OUTPUT);
  digitalWrite(green1, HIGH);
  digitalWrite(red2, HIGH);
  pinMode(buttonPin, INPUT_PULLUP);
}


void loop()
{
  changeLights();
  delay(15000);
}

void changeLights()
{
  digitalWrite(green1, LOW);
  digitalWrite(yellow, HIGH);
  digitalWrite(red2, HIGH);
  delay(3000);

  digitalWrite(yellow, LOW);
  digitalWrite(red1, HIGH);
  digitalWrite(green2, HIGH);
  delay(5000);

  digitalWrite(red2, HIGH);
  digitalWrite(green2, LOW);
  delay(750);

  digitalWrite(green1, HIGH);
} // this ends the changeLights function
{ // this is in error
  // everything from here ..... 
if (digitalRead(buttonPin) == LOW)
{
  if (run == 0)
  {
    run = 255;
  }
  else
  {
    run = 0;
  }


  if (run > 0)
  } 
 // to here is outside of any function, an error
  
void loop()  // 2 loop() functions in one sketch is illegal
{
  if (digitalRead(button) == HIGH) {
    delay(15); // software debounce
    if (digitalRead(button) == HIGH) {
      // if the switch is HIGH, ie. pushed down - change the lights!
      changeLights();
    }
  }
}

void changeLights() // a redefinition of the changeLights function is illegal
{
  // green off, yellow on for 3 seconds
  digitalWrite(green1, LOW);
  digitalWrite(yellow, HIGH);
  delay(3000);

  // turn off yellow, then turn red on for 5 seconds
  digitalWrite(yellow, LOW);
  digitalWrite(red1, HIGH);
  delay(1000);

  digitalWrite(red2, LOW);
  digitalWrite(green2, HIGH);

  delay(5000);
  // turn off red and yellow, then turn on green
  digitalWrite(green2, LOW);

  digitalWrite(red2, HIGH);
  delay(500);

  digitalWrite(red1, LOW);
  digitalWrite(green1, HIGH);
}
}  // extra 
}  // extra

Please read the "how to use the forum" stickies to see how to format and post code. Please post the entire text of any error messages.

Thx for the help but i am a programming nub. I have no idea how to fix it as i took the code from online and modified it to add more lights. Any help with correcting the problem would be appreciated. :smiley:

This is the best that I can do without knowing exactly what you want. This compiles and the lights follow a sequence upon the push of the button. Tested with my Uno and works (for some definitions of works) I replaced the debounce (that really doesn't) with state change detection. The switch must be wired from input to ground (active LOW). Not sure what the run variable was for, it did not really do anything.

int red1 = 10;
int yellow = 9;
int green1 = 8;
int buttonPin = 12;
int red2 = 6;
int green2 = 7;

boolean buttonState = HIGH;  // for state change detection
boolean lastButtonState;     // for state change detection

void setup()
{
  pinMode(red1, OUTPUT);
  pinMode(yellow, OUTPUT);
  pinMode(green1, OUTPUT);
  pinMode(red2, OUTPUT);
  pinMode(green2, OUTPUT);
  digitalWrite(green1, HIGH);
  digitalWrite(red2, HIGH);
  pinMode(buttonPin, INPUT_PULLUP);  // implies switch connected to ground and input, active LOW
}



void loop()  // 2 loop() functions in one sketch is illegal
{  
  // detect change in button state and run sequence on LOW.  No debounce required
  buttonState = digitalRead(buttonPin);
  if (buttonState != lastButtonState)
  {
    if (buttonState == LOW)
    {
      changeLights();
    }
    lastButtonState = buttonState;
  }
}

void changeLights()
{
  // green off, yellow on for 3 seconds
  digitalWrite(green1, LOW);
  digitalWrite(yellow, HIGH);
  delay(3000);

  // turn off yellow, then turn red on for 5 seconds
  digitalWrite(yellow, LOW);
  digitalWrite(red1, HIGH);
  delay(1000);

  digitalWrite(red2, LOW);
  digitalWrite(green2, HIGH);

  delay(5000);
  // turn off red and yellow, then turn on green
  digitalWrite(green2, LOW);

  digitalWrite(red2, HIGH);
  delay(500);

  digitalWrite(red1, LOW);
  digitalWrite(green1, HIGH);
}