-2

When I try to compile the following code in Arduino ,I get the error "expected initializer before 'void'".How can I get the code to work?

const int LED = 9;
const int BUTON = 2


void setup() {
  pinMode (LED, OUTPUT);
  pinMode (BUTON, INPUT);
}

void loop() {
  if (digitalRead(BUTON) == HIGH);
  {
    digitalWrite(LED, HIGH);
  }
  else
  {
    digitalWrite(LED, LOW);
  }
}

closed as off-topic by gre_gor, Michel Keijzers, VE7JRO, Delta_G, MatsK May 30 '18 at 6:34

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question does not appear to be about Arduino, within the scope defined in the help center." – gre_gor, Michel Keijzers, VE7JRO, Delta_G, MatsK
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 2
    This is actually not an Arduino related problem. Everybody that gets into physical computing should have some basic knowledge in C/C++ and the compiling of such code. Using an Arduino on top of that adds complexity and is more difficult to debug if something does not work as intended. So I hereby encourage you to take some tutorials in writing C/C++ to get a feeling of all the traps that lurk at you along your journey. – Kwasmich May 28 '18 at 9:44
4

You are missing a semi-colon after const int BUTON = 2

Each expression should be terminated with a semi-colon. Your code should look like this:

const int LED = 9;
const int BUTON = 2;


void setup() {
  pinMode (LED, OUTPUT);
  pinMode (BUTON, INPUT);
}

void loop() {
  if (digitalRead(BUTON) == HIGH)
  {
    digitalWrite(LED, HIGH);
  }
  else
  {
    digitalWrite(LED, LOW);
  }
}

Not the answer you're looking for? Browse other questions tagged or ask your own question.