0

Sorry if my code isn't well written or anything because I'm new to Arduino and coding in C, but what is wrong with my code?

int sidepin = 2;
int LED = 5;
int val;
void setup() {
  pinMode(sidepin, INPUT);
  pinMode(LED, OUTPUT);
}

void loop() {
  val = digitalRead(sidepin);
  if(val = 0)
  {
    pinMode(LED, HIGH);
  }
  else(val > 0) 
  {
    pinMode(LED, LOW);
  }
}
2
  • 1
    Please help the helpers help you by asking a more specific question than "what's up..." If you need help with compiler errors, say so, and report at least some of the message and the location of it. If you're asking about run-time behavior, please state what you expected it to do and what it actually did. You can get lots of good help here but please try to direct your readers to the specific problem. The guide to asking good questions has a lot of good suggestions. – JRobert Jun 19 '16 at 11:41
  • else(){} looks like bad syntax. – Dave X Jun 20 '16 at 20:15
2

Your IF statement, you're using: (val = 0), and I believe you meant (val == 0).

Also, you're using else(val > 0) and else doesn't need any argument. So the fixed code should look like:

int sidepin = 2;
int LED = 5;
int val;
void setup() {
  pinMode(sidepin, INPUT);
  pinMode(LED, OUTPUT);
}

void loop() {
  val = digitalRead(sidepin);
  if(val == LOW)
  {
    pinMode(LED, HIGH);
  }
  else
  {
    pinMode(LED, LOW);
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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