-2

Arduino Error: Where have i gone wrong in this simple and extremely small amount of code to receive the above error message? I cannot figure it out.

int ledPin = A0;
int bumpPin = A1;
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(bumpPin, INPUT);
}

void loop() {
digitalRead(bumpPin);
if (bumpPin == HIGH);
digitalWrite(ledPin,HIGH);
}else{
digitalWrite(ledPin,LOW);
}
Paul T.
  • 4,703
  • 11
  • 25
  • 29
Steve
  • 11
  • 4

1 Answers1

1

Definitely read a tutorial on C++. What you have here is a basic syntax error. An if/else statements uses the following syntax:

if (condition) {
    // Do stuff here
} else {
    // Do other stuff here
}

You have a semi colon after your condition in your if statement. Change that to a curly brace and you’re good! So this:

if (bumpPin == HIGH);

Should be this:

if (bumpPin == HIGH) {

Here is an online C++ tutorial.

Here is that tutorial’s section on if statements.

Steampunkery
  • 3,839
  • 2
  • 19
  • 28