Go Down

Topic: if else problem (Read 409 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
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy