My program shows some error..Can anyone help me...

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

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

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

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

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.

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)

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).

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... }

Except for the duplicate declaration of pinVal, yes.