0 is not recognized as integer zero ?

o.k. I give up. Why wont this code print "zero" ? Everything I try results in "one".

int Volume;
void setup()
{
Serial.begin(9600);
Volume = 0;
if (Volume = 0) Serial.println("zero");
if (Volume = 1) Serial.println("one");
}
void loop()
{
}

= is not the same as ==

if (Volume == 0) Serial.println("zero");
if (Volume == 1) Serial.println("one");

That works, thanks. I need to go back and study why a Boolean operator is needed for comparing integer values.

alex04032:
That works, thanks. I need to go back and study why a Boolean operator is needed for comparing integer values.

It's not a Boolean operator.

= is an assignment operator.
== is a comparison operator.

So in order to do a comparison, you need to use the comparison operator.

Clarity. Thank you so much.

study why a Boolean operator is needed
It's not a Boolean operator.
== is a comparison operator.

and "Volume == 1" is a boolean expression (may caused the confusion :slight_smile: