please, compare two variables

please doubts basic,

how to compare the value of two variables?

eg

var1 = 1 var2 = 2

if (var1 == var2) { do something; Else if} { do something; }

Can you help me?

thank you

Sergio

Yes, the pseudo-code you posted is basically correct.

http://www.arduino.cc/en/Reference/If http://arduino.cc/en/Reference/Else

byte var1 = 1;
byte var2 = 2;

if (var1 == var2) {
  // the variables are the same!
  }
else {
  // the variables were different!
  }

thanks for the help but lacked information on my part.

have:

Vrsms char [13] = "011983000000" / / phone number String VTRec / / phone number

I get a sms and store the phone number that sent the sms

Serial.println (String (info)); VNumData = String (String (info)); VTRec = (VNumData.substring (32.44));

and need to do:

if (Vrsms == VTRec) { SMS sends the response only to Vrsms else if SMS sends the response only to Vrsms and VTRec }

Can you help me?

Thank very you.

Use the function strcmp for string comparison. And I suggest you don’t use the String class, use char arrays instead :wink:

thank you very much.

ANd when you are comparing floats there is another trick you should know

float var1 = 1.0;
float var2 = sin(355/113/2);
float threshold = 0.001; // to be defined

if ( abs(var1 - var2) < threshold ) 
{
  // the variables are considered the same!
}
else 
{
  // the variables were different!
  }

with floats you always have to use < or > or <= or >= in tests. The == fails quite often

robtillaart:
with floats you always have to use < or > or <= or >= in tests. The == fails quite often

Heck I like to use <= or >= for integers too. Helps cut down on infinite loops and other undesirable behavior when a variable reaches an unanticipated value.

@ tylernt

Very true, especially if the integers are of the volatile kind used in an interrupt! They can be increased an unknown number of times before tested.

thank you very much