system
February 16, 2010, 12:37pm
1
int aPin = 0;
int bPin = 1;
int mtr1Pin = 2;
int mtr2Pin = 3;
void setup()
{
pinMode(mtr1Pin, OUTPUT);
pinMode(mtr2Pin,OUTPUT);
}
void loop()
{
if analogRead(aPin==0)
digitalWrite(mtr1Pin,HIGH);
else
digitalWrite(mtr1Pin,LOW);
if analogRead(bPin==0)
digitalWrite(mtr2Pin,HIGH);
else
digitalWrite(mtr2Pin,LOW);
}
I just wanted to know what error I made in the program
Yot
February 16, 2010, 12:41pm
2
I think it has something to do with { and }'s
http://arduino.cc/en/Reference/Else
Jeroen
ps. Not the right sub-forum. next time post this kind of question in Software/Syntax & Programs
andrew0
February 16, 2010, 12:56pm
3
Nothing wrong with the brackets that I can see. The problem is more likely that
analogRead(aPin==0)
should probably be
analogRead(aPin)==0
or even
analogRead(aPin)<5
to allow for some small fluctuations in the reading around zero.
Andrew
system
February 16, 2010, 12:59pm
4
THe problem was actually with the { }..But I get the same error again after this one...
int aPin = 0;
int bPin = 1;
int mtr1Pin = 2;
int mtr2Pin = 3;
void setup()
{
pinMode(mtr1Pin, OUTPUT);
pinMode(mtr2Pin,OUTPUT);
}
void loop()
{
if analogRead(aPin==0)
{
digitalWrite(mtr1Pin,HIGH);
}
else
{
digitalWrite(mtr1Pin,LOW);
}
if analogRead(bPin==0)
{
digitalWrite(mtr2Pin,HIGH);
}
else
{
digitalWrite(mtr2Pin,LOW);
}
}
system
February 16, 2010, 1:15pm
5
if analogRead(aPin==0)
The first thing that happens here is that aPin is compared to 0. If they are equal, then, an analogRead(true) is executed. If not, an analogRead(false) is executed.
What do have plugged into the true pin? What do you have plugged into the false pin?
You are missing some parentheses, too.
system
February 16, 2010, 1:20pm
6
Err..Which are the true pin and false pin of the analog o/p..Err..Dnt mind if am silly..am new to this programming stuffs...
will this do any good??
if analogRead(aPin,0)
system
February 16, 2010, 1:26pm
7
The analogRead function takes one argument - the pin to read from.
int pinVal = analogRead(aPin);
if(pinVal == HIGH)
{
// Do something...
}
else
{
// Do something else...
}
THe problem was actually with the { }..
There is nothing wrong with the braces in the original post.
There may not be enogh to do exactly what you want it to, but there are enough to keep the compiler happy (assuming the other typos are fixed).
system
February 16, 2010, 1:57pm
9
Ah...
U are cool.. ;D
but..will this work??
int pinVal = analogRead(aPin);
if(pinVal == HIGH)
{
// Do something...
}
else
{
// Do something else...
}
int pinVal = analogRead(bPin);
if(pinVal == HIGH)
{
// Do something...
}
else
{
// Do something else...
}
system
February 16, 2010, 2:33pm
10
Except for the duplicate declaration of pinVal, yes.