Joystick robot controller

Hi all, first of all introduce myself, my name is Eloi and I'm building a robot. These are the characteristics of the robot and its controller:
Controller:

  • 1 Arduino Mega 2560 R3
  • 1 Joystick
  • 5 push buttons
  • One lcd 40x4
  • 1 matrix numbers
  • One antenna rf

robot:

  • 1 Arduino Mega 2560 R3
  • 1 MD22 controller motors (0-255 analog pins)
  • 4 Motors (two are coupled)
  • One lcd 16x2
  • One gps
  • 1 bluetooth
  • 1 Rf Antenna

The problem is this: The system sends and receives data from the joystick perfectly, but not how to do that with a single joystick to control the two motors perfectly.
The robot is as follows:
m1--- ---m2
| |
| |
m1--- ---m2

I need help with the code please, for the moment the robot code I have is this:

#include <LiquidCrystal.h>
#include <Wire.h>

LiquidCrystal lcd(8, 9, 4, 5, 6, 7); 

#define md22Address 0x58                              // address of md 22 (all mode switches on)
#define softReg 0x07                                  // Byte for reading software register
#define motor1 0x01                                   // Byte for first motor
#define motor2 0x02                                   // Byte for second motor
#define accelReg 0x03   
void setup()
{
  Serial.begin(19200);
  Serial3.begin(19200);
  
  //Pantalla
   lcd.begin(16, 2);
}
void loop()
{
a13 = Serial3.parseInt(); 
    // do it again:
   a14= Serial3.parseInt(); 

if(((a13 >= 490 && a13 <= 560) && (a14 >= 490 && a14 <= 560)))
    {
      Wire.beginTransmission(md22Address);                // Set first motor to a speed of 255
      Wire.write(motor1);
      Wire.write(128);
      Wire.endTransmission();
      
      Wire.beginTransmission(md22Address);                // Set second motor to stop
      Wire.write(motor2);
      Wire.write(128);
      Wire.endTransmission();
    }
    else
    {
      int x1 = map(a13, 1023, 0, 0, 255);
      int x2 = map(a14, 1023, 0, 0, 255);
      
       
           Wire.beginTransmission(md22Address);                // Set first motor to speed 0
            Wire.write(motor1);
            Wire.write(x1);
            Wire.endTransmission();
            
            Wire.beginTransmission(md22Address);                // Set second motor to stop
            Wire.write(motor2);
            Wire.write(x1);
            Wire.endTransmission();
  
          lcd.setCursor(0,1);
          lcd.print(x1);
          lcd.print(",      ");
    }

}

Before you're moved, see this thread. look at reply #19.

http://forum.arduino.cc/index.php?topic=262762.msg1855000#msg1855000

El problema es

that this is the English language section of the forum, and your post isn't in English.

Thank you HazarsMins!
And Pauls, I spanish but the post is in english!

And Pauls, I spanish but the post is in english!

Well, it wasn't before. Thanks for making me look like an idiot.

Below is some two pot (like a joystick) test code for controlling servos. Might be somewhat similar to what you are looking for.

//zoomkat dual pot/servo test 12-29-12
//view output using the serial monitor

#include <Servo.h> 
Servo myservoS1;
Servo myservoS2;

int potpinS1 = 0;  //analog input pin A0
int potpinS2 = 1;

int newvalS1, oldvalS1;
int newvalS2, oldvalS2;

void setup() 
{
  Serial.begin(9600);  
  myservoS1.attach(2);  
  myservoS2.attach(3);
  Serial.println("testing dual pot servo");  
}

void loop() 
{ 
  newvalS1 = analogRead(potpinS1);           
  newvalS1 = map(newvalS1, 0, 1023, 0, 179); 
  if (newvalS1 < (oldvalS1-2) || newvalS1 > (oldvalS1+2)){  
    myservoS1.write(newvalS1);
    Serial.print("1- ");
    Serial.println(newvalS1);
    oldvalS1=newvalS1;
  }

  newvalS2 = analogRead(potpinS2);
  newvalS2 = map(newvalS2, 0, 1023, 0, 179);
  if (newvalS2 < (oldvalS2-2) || newvalS2 > (oldvalS2+2)){  
    myservoS2.write(newvalS2);
    Serial.print("2- ");    
    Serial.println(newvalS2);
    oldvalS2=newvalS2;
  }
  delay(50); //slow down looping to better read serial monitor 
}