expected initializer before 'digitalWrite'

const int GREEN_PIN = 10; // pin for green light
const int YELLOW_PIN = 9; // pin for yellow light
const int RED_PIN = 8; // pin for red light
const int button = 12; // switch is on pin 12
void changeLights();

void setup() {
  pinMode(GREEN_PIN, OUTPUT);
  pinMode(YELLOW_PIN, OUTPUT);
  pinMode(RED_PIN, OUTPUT);
  pinMode(button, INPUT);
  digitalWrite(GREEN_PIN, HIGH);
}

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();
            delay(15000); // wait for 15 seconds
}

{
void changeLights()
  //Green off, Yellow on
  digitalWrite(GREEN_PIN, LOW);
  digitalWrite(YELLOW_PIN, HIGH);
  delay(3000);

  //Yellow off, Red on
  digitalWrite(YELLOW_PIN, LOW);
  digitalWrite(RED_PIN,HIGH);
  delay(5000);

  digitalWrite(YELLOW_PIN, HIGH);
  delay(2000);

  digitalWrite(YELLOW_PIN, LOW);
  digitalWrite(RED_PIN, LOW);
  digitalWrite(GREEN_PIN, HIGH);
  delay(3000);
}

Can anyone give some advice on why I'm getting the expected initializer error? It's marking it on the digitalWrite(GREEN_PIN, LOW); line.

:slight_smile:
you defining the function?
then you should put void in the brackets in void changeLights()
i also got this problem, but solved it :slight_smile:
:wink:

move this:

void changeLights()

above the curly brace above it.

then add a few closing braces to complete the loop function. Then it'll compile at least.