Go Down

Topic: if else problem (Read 393 times) previous topic - next topic

int ledPin = 13;
int inputPin = 3;
int val = 0;

void setup()
{
pinMode(ledPin, OUTPUT);
pinMode(inputPin, INPUT);
}

void loop()
{
if (inputPin == val );
 {
   digitalWrite(ledPin, LOW);
 }
if else (inputPin == val);
 {
   digitalWrite(ledPin, HIGH);
}

sketch_dec25b.cpp: In function 'void loop()':
sketch_dec25b:16: error: expected `(' before 'else'
sketch_dec25b:19: error: expected `}' at end of input

what happen i can't understand, pliz help me

el_supremo

The semicolon at the end of this line:
Code: [Select]
if (inputPin == val );
terminates the if statement. So it means "if inputPin equals val, do nothing"

The loop() should be:
Code: [Select]

void loop()
{
if (inputPin == val )
  {
    digitalWrite(ledPin, LOW);
  }
if else (inputPin == val)
  {
    digitalWrite(ledPin, HIGH);
}



Pete


sketch_dec25a.cpp: In function 'void loop()':
sketch_dec25a:16: error: expected `(' before 'else'
sketch_dec25a:19: error: expected `}' at end of input

but it send this error

i have solve it . thank u for your help

int ledPin = 13;
int inputPin = 3;
int val = 0;

void setup()
{
pinMode(ledPin, OUTPUT);
pinMode(inputPin, INPUT);
}

void loop()
{
if (inputPin <= val )
  {
    digitalWrite(ledPin, LOW);
  }
else
  {
    digitalWrite(ledPin, HIGH);
  }
}

Go Up