XBEE sending two values?

Im trying to send two analog values through an xbee. so far I've tryed to use a sync character like this:

The transmitter prints the value 255 then x value BYTE then value 254 then y value BYTE.

so for the reciever i did this:

incomingByte = Serial.read();

if (incomingByte == 255){ x = Serial.read(); } if (incomingByte == 254){ y = Serial.read(); }

Thank you in advance.

Thank you in advance.

You are welcome.

Now, what is the problem?

i can send the two values but when i receive them on the other arduino their combined into one number i need to be able to split them into two variables again.

when i receive them on the other arduino their combined into one number

Only if you combined them. Or didn't send them right. Maybe you need to post all of your sender code and all of the receiver code. Any sample output that you get from the sender and/or receiver would be good to see, too.

I think you need to wait for the bytes to arrive...

while (!Serial.available()) {}
incomingByte = Serial.read();

while (!Serial.available()) {}
if (incomingByte == 255){
x = Serial.read();
}
if (incomingByte == 254){
y = Serial.read();
}

This is my code:
SENDER:

#define xLow  17
#define xHigh 15
#define yLow  16
#define yHigh 14
 
 
void setup(){
  Serial.begin(9600);
  
}
 
void loop(){
  pinMode(xLow,OUTPUT);
  pinMode(xHigh,OUTPUT);
  digitalWrite(xLow,LOW);
  digitalWrite(xHigh,HIGH);
 
  digitalWrite(yLow,LOW);
  digitalWrite(yHigh,LOW);
 
  pinMode(yLow,INPUT);
  pinMode(yHigh,INPUT);
  delay(10);
 

  int x=analogRead(yLow -14);
 
  pinMode(yLow,OUTPUT);
  pinMode(yHigh,OUTPUT);
  digitalWrite(yLow,LOW);
  digitalWrite(yHigh,HIGH);
 
  digitalWrite(xLow,LOW);
  digitalWrite(xHigh,LOW);
 
  pinMode(xLow,INPUT);
  pinMode(xHigh,INPUT);
  delay(10);
 
  int y=analogRead(xLow - 14);
    x = map(x, 0, 1023, 0, 200);
    Serial.print (255, BYTE);
    Serial.print (x, BYTE); 
    Serial.print (254, BYTE);
    Serial.print (y, BYTE); 
}

RECEIVER:

byte incomingByte, x, y;

void setup() {


Serial.begin(9600);
Serial.println("Ready!");
}

void loop() {
if (Serial.available()) {  


while (!Serial.available()) {}
incomingByte = Serial.read();

while (!Serial.available()) {}
if (incomingByte == 255){
x = Serial.read();
}
if (incomingByte == 254){
y = Serial.read();
} 

}
}

I know there is errors can someone try to edit it?

On the receiver, you want to read 4 bytes. So, do nothing unless there are 4 bytes to read:

byte a, x, y;
void loop()
{
   if(Serial.available() >= 4)
   {
      x = 0;
      y = 0;

      // Read first 2 bytes
      a = Serial.read();
      if(a == 255) // Next byte goes in x
         x = Serial.read();
      else if(a == 254) // Next byte goes in y
         y = Serial.read();
      else // Next byte gets ignored
         a = Serial.read();

      // Read next 2 bytes
      a = Serial.read();
      if(a == 255) // Next byte goes in x
         x = Serial.read();
      else if(a == 254) // Next byte goes in y
         y = Serial.read();
      else // Next byte gets ignored
         a = Serial.read();
   }
}

I think, though, that you’d be better off having the sender send the data as text:

<x=189,y=45>

Then, you know where a packet starts (<), where it ends (>), and where the values in the packet start (after the =) and end (at the , or >). Any packet that does not contain a <, a >, a comma, and 2 equal signs is incomplete, and should be discarded.

By the way, you never told us what the problem is with this code. Does it work, or not? If not, what indication do you have that it isn’t working? If it works, what’s the problem?