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
Combining strings from XBee Adapter kit - v1.1
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- chrisnet
- Posts: 70
- Joined: Mon Jun 04, 2012 11:05 am
- adafruit_support_bill
- Posts: 88087
- Joined: Sat Feb 07, 2009 10:11 am
Re: Combining strings from XBee Adapter kit - v1.1
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:
You might try casting to a character as in:
Code: Select all
1pos = String((char)mySerialX.read());
2pos = String((char)mySerialX.read());
- chrisnet
- Posts: 70
- Joined: Mon Jun 04, 2012 11:05 am
Re: Combining strings from XBee Adapter kit - v1.1
Thanks,
I dont know what I was thinking! Thanks for helping
I dont know what I was thinking! Thanks for helping
Please be positive and constructive with your questions and comments.