novato en apuros auxilio

cordial saludo

Estoy trabajando en un proyecto del tanque a control a distancia por medio de bluethoo, soy novato en estos temas pero me pareció una actividad de tiempo libre para compartir con mi hijo e investigado y encontrabajo varios tutoriales, que me han servido y he encontrado varios codigos, en este caso quiero agregarle un servomotor, encontre 2 programas los cuales quiero unir me prodrian explicar como hacerlo:

Codigo 1 servomotor

Creado: Luis del Valle (ldelvalleh@programarfacil.com)
https://programarfacil.com

*/

// Incluímos la librería para poder controlar el servo
#include <Servo.h>

// Declaramos la variable para controlar el servo
Servo servoMotor;

void setup() {
// Iniciamos el monitor serie para mostrar el resultado
Serial.begin(9600);

// Iniciamos el servo para que empiece a trabajar con el pin 9
servoMotor.attach(9);
}

void loop() {

// Desplazamos a la posición 0º
servoMotor.write(0);
// Esperamos 1 segundo
delay(1000);

// Desplazamos a la posición 90º
servoMotor.write(90);


Codigo 2 motores 

#include <AFMotor.h>

AF_DCMotor motor2(2, MOTOR12_64KHZ); // create motor #2, 64KHz pwm
AF_DCMotor motor1(1, MOTOR12_64KHZ);

int state = 0;

void setup() 
{
Serial.begin(9600);           // set up Serial library at 9600 bps
Serial.println("Welcome: Forward = 1 Left = 2 Right = 3 Backwards = 4 Stop = 0");
motor2.setSpeed(200);     // set the speed to 200
motor1.setSpeed(200);     // set the speed to 200
}


void loop() {
//if some data is sent, read it and save it in the state variable
if(Serial.available() > 0)
{
  state = Serial.read();
  Serial.print("I received: ");
  Serial.println(state);
  delay(10);

  if (state == '0') 
  {
    motor2.setSpeed(200);     // set the speed to 200/255
    motor1.setSpeed(200);     // set the speed to 200/255
    motor2.run(RELEASE);      // turn it on going forward
    motor1.run(RELEASE);      // turn it on going forward
    Serial.println("Stopped");
    delay(100);
    state = 0; 
  }
  
  else if (state == '1')      // If 1 Forwards
  {
    motor2.run(RELEASE);      // turn it on going forward
    motor1.run(RELEASE);      // turn it on going forward
    motor2.setSpeed(200);     // set the speed to 200
    motor1.setSpeed(200);     // set the speed to 200
    motor2.run(FORWARD);      // turn it on going forward
    motor1.run(FORWARD);      // turn it on going forward
    Serial.println("Forward");
    delay(100);
    state = 0; 
  }
  
  else if (state == '2')      // If 2 Turn Left
  { 
    motor2.run(RELEASE);      // turn it on going forward
    motor1.run(RELEASE);      // turn it on going forward  
    motor1.setSpeed(255);     // set the speed to 200/255
    motor1.run(FORWARD);
    //motor2.run(BACKWARD);      
    Serial.println("Left");
    delay(100);
    state = 0;     
  }
  
  else if (state == '3') {    // If 3 Turn Right
    motor2.run(RELEASE);      // turn it on going forward
    motor1.run(RELEASE);      // turn it on going forward
    motor2.setSpeed(255);     // set the speed to 255
    motor2.run(FORWARD);      
    //motor1.run(BACKWARD);    
    Serial.println("Right");
    delay(100);
    state = 0;  
  }
  
  else if (state == '4')       // If 4 Backwards
  {
    motor2.run(RELEASE);      // turn it on going forward
    motor1.run(RELEASE);      // turn it on going forward
    motor2.setSpeed(200);      // set the speed to 200
    motor1.setSpeed(200);      // set the speed to 200
    motor2.run(BACKWARD);      // Motor 2 backwards
    motor1.run(BACKWARD);      // Motor 1 backwards
    Serial.println("Backward");
    delay(100);
    state = 0;   
  }
  
  else if (state == '5') 
  {
    motor2.run(RELEASE);      // turn it on going release
    motor1.run(RELEASE);      // turn it on going release
    motor2.setSpeed(255);     // set the speed to 255
    motor1.setSpeed(140);     // set the speed to 140
    motor2.run(FORWARD);      // Motor 2 forward
    motor1.run(FORWARD);      // Motor 1 forward
    Serial.println("Forward Right");
    delay(100);
    state = 0;   
   }
   
   else if (state == '6') 
  {
    motor2.run(RELEASE);      // turn it on going release
    motor1.run(RELEASE);      // turn it on going release
    motor1.setSpeed(255);     // set the speed to 255
    motor2.setSpeed(140);     // set the speed to 140
    motor2.run(FORWARD);      // Motor 2 forward
    motor1.run(FORWARD);      // Motor 1 forward
    Serial.println("Forward Left");
    delay(100);
    state = 0;   
   }
   
   else if (state == '7')       // If 4 Backwards
  {
    motor2.run(RELEASE);      // turn it on going forward
    motor1.run(RELEASE);      // turn it on going forward
    motor1.setSpeed(255);     // set the speed to 255
    motor2.setSpeed(140);     // set the speed to 140
    motor2.run(BACKWARD);      // Motor 2 backwards
    motor1.run(BACKWARD);      // Motor 1 backwards
    Serial.println("Backward Right");
    delay(100);
    state = 0;   
  }
  
  else if (state == '8')       // If 4 Backwards
  {
    motor2.run(RELEASE);      // turn it on going forward
    motor1.run(RELEASE);      // turn it on going forward
    motor2.setSpeed(255);     // set the speed to 255
    motor1.setSpeed(140);     // set the speed to 140
    motor2.run(BACKWARD);      // Motor 2 backwards
    motor1.run(BACKWARD);      // Motor 1 backwards
    Serial.println("Backward Left");
    delay(100);
    state = 0;   
  }
  
  else if (state >= '9')
  {
    Serial.println("Invalid");
    delay(100);
    state = 0; 
  }
}
}

Les estaria altamente agradecido por su orientacion y apoyo

¡Hola Iguerre10! Antes que nada, quería recomendarte usar para escribir código y que el titulo de la publicación sea más especifico, al estilo "Combinar dos programas". Además, decirte que, en caso de que no lo hayas hecho, pruebes primero ambos programas por separado, y entiendas el funcionamiento de ambos, te facilitará mucho el combinarlos.

Ahora, unir ambos programas es muy simple, escribí lo que está antes del setup, antes de este, lo que va dentro del setup, dentro del setup, y lo que va dentro del loop, dentro del loop (Válgase la redundancia).

Podes dividir el programa así:

-Inclusión de librerías
-Variables y objetos
-Setup
-Loop

Se cuidadoso de no repetir instrucciones innecesariamente, por ejemplo, en el primer código, inicializaste el serial pero no lo usaste, en cambio en el segundo código, si lo usaste, no es necesarios que uses Serial.begin(9600); dos veces al combinar el programa.

Asegurate de haber descargado la libraría para los 2 motores, la de Servo viene incluida en arduino, pero no la otra, descargala y agregala en la carpeta "libraries" que se encuentra donde arduino está instalado, si es un .zip, anda a Arduino y pone:

Programa -> Incluir librería -> Añadir librería .zip

¡Saludos y espero que te sirva!