Making a xbee based joystick control for six servos to hold position

i have make the code but it cant work as i want when i release the joy stick servos position will come back simply they trace the position of joy stick.but cant hold the position of servos where i want my tx and rx code are given please correct the code for me iam new user i dont know about the programming

tx code is

int potPin0 = 0;
int potPin1 = 1;
int potPin2 = 2;
int potPin3 = 3;
int potPin4 = 4;
int potPin5 = 5;
void setup()
{
//Create Serial Object (9600 Baud)
Serial1.begin(9600);
}

void loop()
{
int val0 = map(analogRead(potPin0), 0, 1023, 0, 180);
Serial1.write(val0);
delay(50);

int val1 = map(analogRead(potPin1), 0, 1023, 0, 180);
Serial1.write(val1);
delay(50);

int val2 = map(analogRead(potPin2), 0, 1023, 0, 180);
Serial1.write(val2);
delay(50);

int val3 = map(analogRead(potPin3), 0, 1023, 0, 180);
Serial1.write(val3);
delay(50);

int val4 = map(analogRead(potPin4), 0, 1023, 0, 180);
Serial1.write(val4);
delay(50);

int val5 = map(analogRead(potPin5), 0, 1023, 0, 180);
Serial1.write(val5);
delay(50);

}

rx code is

//Include Servo Library
#include <Servo.h>

//Define Pins
int servo1Pin = 3;
int servo2Pin = 5;
int servo3Pin = 6;
int servo4Pin = 9;
int servo5Pin = 10;
int servo6Pin = 11;

//Create Servo Object
Servo servo1;
Servo servo2;
Servo servo3;
Servo servo4;
Servo servo5;
Servo servo6;
void setup()
{
//Start Serial
Serial.begin(9600);

//Attaches the Servo to our object
servo1.attach(servo1Pin);
servo2.attach(servo2Pin);
servo3.attach(servo3Pin);
servo4.attach(servo4Pin);
servo5.attach(servo5Pin);
servo6.attach(servo6Pin);
}

void loop()

{
while(Serial.available() == 0);

int data1 = Serial.read();
int pos1 = data1;
pos1 = constrain(pos1, 0, 180);

servo1.write(pos1);

while(Serial.available() == 0);

int data2 = Serial.read();
int pos2 = data2;
pos2 = constrain(pos2, 0, 180);

servo2.write(pos2);

while(Serial.available() == 0);

int data3 = Serial.read();
int pos3 = data3;
pos3 = constrain(pos3, 0, 180);

servo3.write(pos3);

while(Serial.available() == 0);

int data4 = Serial.read();
int pos4 = data4;
pos4 = constrain(pos4, 0, 180);

servo4.write(pos4);

while(Serial.available() == 0);

int data5 = Serial.read();
int pos5 = data5;
pos5 = constrain(pos5, 0, 180);

servo5.write(pos5);

while(Serial.available() == 0);

int data6 = Serial.read();
int pos6 = data6;
pos6 = constrain(pos6, 0, 180);

servo6.write(pos6);

}

tx_servo.ino (742 Bytes)

rx_servo.ino (1.32 KB)