Poll
Question: anybody can help me
if else - 1 (50%)
if else problem - 1 (50%)
Total Voters: 2

Pages: [1]   Go Down
Author Topic: if else problem  (Read 330 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Offline Offline
Edison Member
*
Karma: 35
Posts: 1429
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

The loop() should be:
Code:
void loop()
{
 if (inputPin == val )
  {
    digitalWrite(ledPin, LOW);
  }
 if else (inputPin == val)
  {
    digitalWrite(ledPin, HIGH);
}


Pete
Logged

Where are the Nick Gammons of yesteryear?

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


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
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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);
  }
}
Logged

Pages: [1]   Go Up
Jump to: