Glad it helped!
Beware, there are a few traps in that code for those new to C, particularly where it pertains to string handling.
For example:
char caption[8];
This means your string can be 7 characters long, plus the terminating null (ASCII 0x00). When you define a literal string:
char caption[8] = "RIGHT_Y";
... the assignment is allowed when you initialize the char array, but you can't just go around assigning strings that way anywhere else. For instance, this wouldn't work:
char caption[8];
void setup () {
caption = "LEFT_X";
}
void loop () {
xbee.print(caption);
....
}
The problem here is that "LEFT_X" is an anonymous array of char, which is stored at a particular memory address. You don't actually copy that string to caption, you just set caption (which is essentially a pointer to char) to the memory address where the string literal currently exists. By the time you've left setup() and entered loop(), that memory is technically no longer allocated -- and in fact, may have been *re-*allocated to something else. In other words, caption is going to point to whatever happens to be at that memory location, and it may no longer be the text you intended.
That is why strcpy() exists -- it assigns the contents of a string (another variable or a literal) to a variable. It stops when it finds a Null. String literals always contain a terminating null. When you define a char array, it's important you define it to <length of text + 1> and make sure the byte following your last text character is 0x00. (Again, strcpy() will take care of this.) Make sure the array is long enough for this whole string, otherwise you'll write over whatever existed in memory after your char array. Could be nothing, could be something.
Similarly, you can't compare char arrays and string literals like this:
char caption[8] = "LEFT_X";
void loop () {
...
if (caption == "LEFT_X") {
// This doesn't work
}
...
}
... because what you are really asking is "is the address contained by caption equal to the address of this anonymous string literal?" This should always fail. Instead, you need to do this:
if (strcmp(caption, "LEFT_X") == 0) {
// This works
}
The strcmp() function works the same as strcpy() ... it compares the bytes at the respective memory addresses one at a time, until it encounters a null. If they're the same, it returns 0. (It returns positive and negative numbers to tell you which string is "greater", which you won't usually be interested in, but it's worth knowing.)
Apologies if you already know how to deal with C strings, but it's not obvious, and not intuitive until you know.