Combining strings from XBee Adapter kit - v1.1

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
chrisnet
 
Posts: 70
Joined: Mon Jun 04, 2012 11:05 am

Combining strings from XBee Adapter kit - v1.1

Post by chrisnet »

I am trying to combine two variables and need a little help here is the code


String 1pos, 2pos, Id;

void readNumber(void) // Read the Xbee
{
mySerialX.listen();
if(mySerialX.available()){
1pos = String(mySerialX.read());
2pos = String(mySerialX.read());

Id = String(1pos + 2pos);

Serial.println(Id);
delay(500);
}
}

I get 6568 when I need to get "AD"

Thanks for any help

User avatar
adafruit_support_bill
 
Posts: 88087
Joined: Sat Feb 07, 2009 10:11 am

Re: Combining strings from XBee Adapter kit - v1.1

Post by adafruit_support_bill »

65 is the numeric value of the character "A" and 68 is the numeric value of "D". The string constructor thinks you are passing it an integer and is giving you the string representation of it.

You might try casting to a character as in:

Code: Select all

1pos = String((char)mySerialX.read());
2pos = String((char)mySerialX.read());

User avatar
chrisnet
 
Posts: 70
Joined: Mon Jun 04, 2012 11:05 am

Re: Combining strings from XBee Adapter kit - v1.1

Post by chrisnet »

Thanks,

I dont know what I was thinking! Thanks for helping

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”