Joystick doesn't work and 5-position switch works over XBee communication

I am trying to use a joystick connected to one Arduino UNO board to control servos connected to another Arduino UNO board over XBee communication but I couldn’t get the project to work. If I use 5-position switch connected to one Arduino UNO board to control servos connected to another Arduino UNO board over XBee communication, it works. I think that XBee modules can’t send or receive analog signals without special set up of XBee modules. The XBee modules are on XBee SIP adapters. I don’t have XBee 5V/3.3V Adapter Boards. I have “Getting Started with XBee RF Modules” e-book but it is written for BASIC Stamp microcontrollers. There is a project in the e-book on using a joystick connected to one BASIC Stamp board to control the Boe-Bot robot. The project calls for Parallax ServoPal (#28824) which is no longer made. My joystick project doesn’t work because the servos kept on running when the joystick is at the center position. The servos should not be running when the joystick is at the center position. How can I get the code working?

#include <SoftwareSerial.h>
const byte PIN_ANALOG_X = 0;
const byte PIN_ANALOG_Y = 1;
const int X_THRESHOLD_LOW = 400; //I have the contrains real big so there's less chance for
const int X_THRESHOLD_HIGH = 600; //analog misinterpretation.
const int Y_THRESHOLD_LOW = 400;
const int Y_THRESHOLD_HIGH = 600;
int x_position;
int y_position;
int x_direction;
int y_direction;
const int xb_rx = 2;
const int xb_tx = 3;
SoftwareSerial Xbee(xb_rx, xb_tx);
void setup() 
{
  Serial.begin(9600);
  Xbee.begin(9600);
}
void loop () 
{
  x_direction = 0;
  y_direction = 0;
  x_position = analogRead(PIN_ANALOG_X);
  y_position = analogRead(PIN_ANALOG_Y);
  //Serial.print(x_position);
  //Serial.print(y_position);
  if (x_position > X_THRESHOLD_HIGH) 
  {
    x_direction = 1;
  }
  else if (x_position < X_THRESHOLD_LOW) 
  {
    x_direction = -1;
  }
  if (y_position > Y_THRESHOLD_HIGH) 
  {
    y_direction = 1;
  } 
  else if (y_position < Y_THRESHOLD_LOW) 
  {
    y_direction = -1;
  }
  if (x_direction == -1) 
  {
    if (y_direction == -1) 
    {
      Serial.println("left-down");
    }
    else if (y_direction == 0) 
    {
      Serial.println("a"); //the A is whats making it go left
      Xbee.println("a");
    }
    else
    {
// y_direction == 1
      Serial.println("left-up");
    }
  }
  else if (x_direction == 0) 
  {
    if (y_direction == -1) 
    {
      Serial.println("s"); // S is for reverse
      Xbee.println("s");
    }
    else if (y_direction == 0) 
    {
      Serial.println("f"); // F is for Stop--it sends this until something else is sent
      Xbee.println("f");
    }
    else 
    {
// y_direction == 1
      Serial.println("w"); // W is forward
      Xbee.println("w");
    }
  }
  else
  {
// x_direction == 1
    if (y_direction == -1) 
    {
      Serial.println("right-down");
    }
    else if (y_direction == 0) 
    {
      Serial.println("d"); // D is right
      Xbee.println("d");
    }
    else 
    {
// y_direction == 1
      Serial.println("right-up");
    }
  }
}
#include <SoftwareSerial.h>
#include <Servo.h> 
Servo servoLeft;
Servo servoRight;
const int xb_rx = 2;
const int xb_tx = 3;
SoftwareSerial Xbee(xb_rx, xb_tx);
void setup(void)
{
  servoLeft.attach(5);
  servoRight.attach(6);
  Serial.begin(9600);
  Xbee.begin(9600);
  servoLeft.write(90);
  servoRight.write(90);
  
}
void loop(void)
{
  while (Xbee.available() == 0) {}
  char val = Xbee.read();
  switch(val) // Perform an action depending on the command
  {
    case 'w'://Move Forward
    forward();
    //Serial.println("w");
    break;
    case 's'://Move Backwards
    reverse();
    //Serial.println("s");
    break;
    case 'a'://Turn Left
    left();
    //Serial.println("a");
    break;
    case 'd'://Turn Right
    right();
    //Serial.println("d");
    break;
    case 'f'://Stop
    stopmotors();
    //Serial.println("f");
    break;
  }
}
void stopmotors() //Stop
{
  servoLeft.write(90);
  servoRight.write(90);
}
void forward()
{
  servoLeft.write(0);
  servoRight.write(180);
}
void reverse()
{
  servoLeft.write(180);
  servoRight.write(0);
}
void left()
{
  servoLeft.write(0);
  servoRight.write(0);
}
void right()
{
  servoLeft.write(180);
  servoRight.write(180);
}

The code came from http://www.instructables.com/id/DFRobotShop-Rover-wXbee/

My joystick project doesn’t work because the servos kept on running when the joystick is at the center position.

Unless I missed it, you don’t send a “stop” signal when the joystick is centered.

The code to decide what to send if way too confusing. You have 9 possibilities, for each position the joystick can be in. It would be far simpler to send 0 to 8 to say which position the joystick is in.

I modified the code so that it sends 1 to 8 and I can see 1 thru 8 on Serial Monitors. Putting the joystick at the center position should stop the servos because the Arduino board sends ‘5’ to the Arduino board with servos. The Arduino board with servos receives ‘5’ but the servos won’t stop. The servos are connected to separate power source and there is common ground.

#include <SoftwareSerial.h>
#include <Servo.h> 
Servo servoLeft;
Servo servoRight;
const int xb_rx = 2;
const int xb_tx = 3;
SoftwareSerial Xbee(xb_rx, xb_tx);
void setup(void)
{
  servoLeft.attach(5);
  servoRight.attach(6);
  Serial.begin(9600);
  Xbee.begin(9600);
  servoLeft.writeMicroseconds(1500);
  servoRight.writeMicroseconds(1500);
  
}
void loop(void)
{
  while (Xbee.available()>0) 
  {
    char val01 = Xbee.read();
    switch(val01)
    {
      case '5':
      servoLeft.writeMicroseconds(1500);
      servoRight.writeMicroseconds(1500);
      Serial.println("5");
      break;
      case '8':
      servoLeft.writeMicroseconds(1000);
      servoRight.writeMicroseconds(2000);
      Serial.println("8");
      break;
      case '2':
      servoLeft.writeMicroseconds(2000);
      servoRight.writeMicroseconds(1000);
      Serial.println("2");
      break;
      case '4':
      servoLeft.writeMicroseconds(1000);
      servoRight.writeMicroseconds(1000);
      Serial.println("4");
      break;
      case '6':
      servoLeft.writeMicroseconds(2000);
      servoRight.writeMicroseconds(2000);
      Serial.println("6");
      break;
      case '1':
      Serial.println("1");
      break;
      case '3':
      Serial.println("3");
      break;
      case '7':
      Serial.println("7");
      break;
      case '9':
      Serial.println("9");
      break;
    }  
  }
}

The values that cause a continuous rotation servo to move the fastest in each direction, or to stop, are approximately 2000, 1000, and 1500. The exact values for your servos need to be determined experimentally. The actual value to stop the servo may be higher or lower than 1500.