help switching between manual and remote control of rover.

I have been playing around with the code for some time now and have gotten my rover to work with Bluetooth control and also with a ping sensor in a autonomous way. the problem is that I do not know how to have a serial command chose one or the other at the start of the program. the code is very rough and i plan on cleaning it up and improving it soon. I have a automaticDrive() and a reomoteDrive() function in there I just need to chose one at the start of the program, how could i do this?

#include <Servo.h>
#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_PWMServoDriver.h"

Adafruit_MotorShield AFMS = Adafruit_MotorShield();

//create motor objects.
Adafruit_DCMotor*frontRight = AFMS.getMotor(1);
Adafruit_DCMotor*frontLeft = AFMS.getMotor(2);
Adafruit_DCMotor*backRight = AFMS.getMotor(3);
Adafruit_DCMotor*backLeft = AFMS.getMotor(4);

Servo headServo;//create servo object.
Servo claw; //min 10   max 65.

int clawPos = 60;//start position of the claw.
int mSpeed = 90;//speed of the wheels 55 - 255'.
int turnSpeed = 150;//speed of mototrs while turning.
int fullTurnDelay = 500; // time that the rover turns.
int servoPositon = 0;// hold the position of the servo.
int option;// hold the choice of manuel or automatic.
int left;
int right;
int semiLeft;
int semiRight;
int front;
int x = 0;//used for loop limiting.
int time;//hold the time since program start.
int dir[5];//array used for directions.
const int echoPin = 11;//pin for the ping sensor.
const int  trigPin = 12;//pin for the ping sensor.
const int objDist = 25; // the distance that the robot will react to objects in (CM).
int moveDir;


void setup()
{  
  //start serial monitor.
  Serial.begin(9200);
  Serial.println("Welcome to PROJECT ROVER\nBy: BRYAN SO");
  pinMode(trigPin,OUTPUT);
  pinMode(echoPin,INPUT);
  AFMS.begin();
  //set the wheels to go at specified speed.
  changeSpeed(mSpeed);
  headServo.attach(9);
  claw.attach(10);
  headServo.write(94);
  claw.write(clawPos);
  
}

//-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-

void loop()
{
  
}
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
void remoteDrive()
{
  while(x<1)
  {
  Serial.println("remote");
  x++;
  }
  if(Serial.available()>0)
  {
  moveDir = Serial.read();
  switch(moveDir)
  {
    case 48: //ASCII #0
      roverForward();
      delay (500);
      Serial.println("forward");
      break;
    case 50: //ASCII #2
      roverBack();
      delay (500);
      Serial.println("Backward");
      break;
    case 52: //ASCII #4
      roverLeft();
      delay (500);
      Serial.println("Left");
      break;
    case 54: //ASCII #6
      roverRight();
      delay (500);
      Serial.println("right");
      break;
    case 45: //ASCII -
      if(clawPos > 29){
        claw.write(clawPos - 15);
        clawPos -= 15;
      }
      else
        Serial.println("to tight");
        break;
    case 61: //ASCII =if(clawPos > 29)
      if(clawPos < 46){
        claw.write(clawPos + 15);
        clawPos += 15; 
      }
      else
        Serial.println("to big");
        break;
    case 56: //ASCII #8
      automaticDrive();
      break;
  }
      
  }
  else{
    roverStop();
    
  }
}
  
void automaticDrive()
{
  
  while(x<1)
  {
  Serial.println("auto");
  x++;
  }
  headServo.write(94);
  delay (200);
  int dist = ping();
  if (dist >=objDist) //if there is nothing in front of the robot.
  {
    changeSpeed(mSpeed);
    roverForward();
  }
  else if(dist < objDist) //if there is somthing in front of the robot.
  {
    roverStop();
    delay(100);
    int reVal = servoPing();//data = 0-5 depending on the conditons.
    /*determine which direction has the most space and
     if there is no space in any direcion. it will then return a value
     of 0 - 5 depending on the situations.*/
    Serial.print("I'm turning ");
    switch(reVal){
      /* in the case that all directions are blocked, the rover will move
      backwards to a certain point then check left and right and turn in
      one of the 2 directions*/
    case 5:
      roverBack();//moves backwards
      delay (1000);
      Serial.println("backwards");
      roverStop();
      reVal = servoPing();
      switch(reVal)
      {
      case 3:
        roverRight(); //90 degrees right
        delay(fullTurnDelay);
        Serial.println("Right");
        break;
      default:
        roverLeft();//90 degrees left
        delay(fullTurnDelay);
        Serial.println("Left");
        break;
      }
      break;
    case 4:
      roverForward();
      Serial.println("\n nevermind, i'n not turning");
      Serial.println("somthing moved put of the way!!");
      break;
    case 0:
      roverLeft();//90 degrees left
      delay(fullTurnDelay);
      Serial.println("Left");
      break;
    case 3:
      roverRight(); //90 degrees right
      delay(fullTurnDelay);
      Serial.println("Right");
      break;
    case 1:
      roverLeft(); //45 degrees left
      delay(300);
      Serial.println("Semi Left");
      break;
    case 2:
      roverRight(); //45 degrees right 
      delay(300);
      Serial.println("Semi Right ");
    }
    Serial.println("======================");
  }
}

//========================================================================
//rover movement & directions FORWARD, BACKWARD, or RELEASE.
void roverStop(){
  frontRight->run(RELEASE);
  frontLeft->run(RELEASE);
  backRight->run(RELEASE);
  backLeft->run(RELEASE);
}
void roverForward(){
  frontRight->run(FORWARD);
  frontLeft->run(FORWARD);
  backRight->run(FORWARD);
  backLeft->run(FORWARD);
}
void roverLeft(){
  changeSpeed(turnSpeed);
  frontRight->run(FORWARD);
  frontLeft->run(BACKWARD);
  backRight->run(FORWARD);
  backLeft->run(BACKWARD);
}

void roverRight(){
  changeSpeed(turnSpeed);
  frontRight->run(BACKWARD);
  frontLeft->run(FORWARD);
  backRight->run(BACKWARD);
  backLeft->run(FORWARD);
}

void roverBack(){
  frontRight->run(BACKWARD);
  frontLeft->run(BACKWARD);
  backRight->run(BACKWARD);
  backLeft->run(BACKWARD);
}

void changeSpeed(int s){
  frontRight->setSpeed(s);
  frontLeft->setSpeed(s);
  backRight->setSpeed(s);
  backLeft->setSpeed(s);
}
//======================================================================
/*sends the direction that the servo will turn to (5-175) 
 then the distance for each direction will be saved. */
int servoPing()
{
  //variables for ping readings in specified directions.
  //calls the servoData and recieves a distance for each dir.
  headServo.write(9);
  Serial.println("==========================");
  delay(300);
  left = servoData(9);
  delay (300);
  dir[0]=left;
  semiLeft = servoData(64);
  delay (300);
  dir[1]=semiLeft;
  front = servoData(94);
  delay (300);
  dir[4]=front;
  semiRight = servoData(124); 
  delay (300);
  dir[2]=semiRight;
  right = servoData(179);
  delay (300);
  dir[3]=right;
  headServo.write(94); //make servo/ping sensor face forwords.
  int number = 0;//the number contained within the array.
  int numberSlot;//a possition in the array.
  for(int x=0; x<=3; x++)
  {
    if(dir[x]> number)
    {
      number =dir[x];
      numberSlot = x;
    }
  }
  if (front > objDist+3){
    return 4;
  }
  else if (number > objDist){
    return numberSlot;
  }
  else{
    return 5;//if there is no open direction. 
  }
}


/* rotates the main servo to a direction thats 
 passed over and returns the ping distance reading*/
long servoData(int a)
{
  headServo.write(a);
  delay(100);
  int sense = ping();
  delay(50);
  return sense;
}


/*gets the reading from the ping sensor and then 
 returnes the distance */
long ping()
{
  long duration,distance;

  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);

  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);

  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin,HIGH);
  distance = duration / 58.2;
  delay(75); // time between ping checks.
  Serial.println(distance);
  return distance; 
}

the problem is that I do not know how to have a serial command chose one or the other at the start of the program.

The problem is more basic than that. The problem is that you aren’t reading serial data. Therefore, you have nothing to make a decision based on.

If there is serial data, read it. If it is an ‘A’, do autonomous mode. If it is an ‘M’, do manual mode. If it is neither, do nothing.

I have had multiple attempts to get it working. I have tried taking the serial input in all of the attempts. But none of them have worked, so I removed it from the setup and loop. I have success full gotten the serial input to work for Manuel commands but when ever I try to switch between manual and automatic it reads the command but doesn't proceed into the functions.

I have success full gotten the serial input to work for Manuel commands but when ever I try to switch between manual and automatic it reads the command but doesn't proceed into the functions.

Can't help without seeing some code.

this is what somthing that i tried.

void loop()
{
  while (x<1)
  {
   Serial.print("print");
  option = Serial.read();
 x++; 
  }
  if (option == 1)
  remoteDrive();
  else 
  automaticDrive();
}

i think the problem is that it does not wait for the serial input from me and just continues to the automatic drive.