Newbie question about boolean variables

I'm just wondering why this test code doesn't work...

int id1=0;
boolean test1=false;

void setup()
{
Serial.begin(9600);
}

void loop()
{
if (Serial.available()>0)
{
id1=Serial.read();
test1=(id1=='A');
if (id1==true)
{
Serial.println(test1);
}
}
}

If I enter 'A' in the serial monitor I get no response. If I comment out the if() statement like so:

//if (id1==true)
//{
Serial.println(test1);
}//
}
}

I get a '1' when I enter an 'A' and a '0' when I enter any other character. What's going on??

Thanks!!

 id1=Serial.read();
    test1=(id1=='A');
    if (id1==true)

id1 contains whatever character you entered.
test1 contains 1 if id1 contains 'A', 0 otherwise.

if (id1==true)

id1 is assigned the value read by Serial.read(). So if id1 is 'A' there's no way it can equal true.

Pete

Ah I see. Code should read: "if (test1==true)" not "if (id1==true)". Thanks a lot for your help :smiley:

And by the way...

At the risk of starting a religious war,

"if (test1)" is functionally identical to "if (test1==true)"