how to control 2 dc motors wirelessly through Bluetooth joystick

hi, everyone! I am making a Life-Size phone and RC Bluetooth controlled BB8 Astromech droid and I am having troubles in the RC part. I already have finished the code for controlling the 2wd droid through the phone, but I have no idea how to do the RC Bluetooth controller part. for that part, I am going to use 1 joystick in the pins A0 for x and A1 for Y. the problem is that the library I am using for the motors makes the total values for the motors 255 for full forward and -255 for full backward, and the joystick goes all the way from 0-1023 and the normal(joystick in its home position which would put the motor in vel=0 )is 520 for y and 512 for x.
I am still quite a c++ noob (i am 12 Years-Old)and would really appreciate the help.

thanks to everyone in advance!

ps: I am using an Arduino UNO.
the BB8 code:

#include <Servo.h>
Servo myservo;
#include <AFMotor.h> //import your motor shield library

AF_DCMotor motor1(1,MOTOR12_64KHZ); // set up motors.
AF_DCMotor motor2(2, MOTOR12_8KHZ);

char dataIn=‘S’;
char determinant;
char det;
int vel = 200; //Bluetooth Stuff

void setup(){

Serial.begin(9600); // begin serial communitication
Serial.println(“Motor test!”);

motor1.setSpeed(105); //set the speed of the motors, between 0-255
motor2.setSpeed(105);

myservo.attach(6);delay(100);
myservo.write(90);delay(100);

}

void loop(){ det = check(); // You’ll need to reconstruct this if your not using the Pololu Dual VNH5019

while (det == ‘F’) // F, move forward
motor1.setSpeed(vel);
motor2.setSpeed(vel);
while (det == ‘B’) // B, move back
motor1.setSpeed(-vel);
motor2.setSpeed(-vel);

while (det == ‘L’) // L, move wheels left
motor1.setSpeed(-vel);
motor2.setSpeed(vel);
while (det == ‘R’) // R, move wheels right
motor1.setSpeed(vel);
motor2.setSpeed(-vel);
while (det == ‘I’) // I, turn right forward
motor1.setSpeed(vel);
motor2.setSpeed(vel/2);

while (det == ‘J’) // J, turn right back
motor1.setSpeed(-vel);
motor2.setSpeed(-vel/2);

while (det == ‘G’) // G, turn left forward
motor2.setSpeed(vel);
motor1.setSpeed(220);

while (det == ‘H’) // H, turn left back
motor2.setSpeed(-vel/2);
motor1.setSpeed(-vel);

while (det == ‘S’) // S, stop
motor1.setSpeed(0);
motor2.setSpeed(0);
//---------------------Toggle switch code------------------//
while (det == ‘W’){myservo.write(180);delay(100);det = check();}
while (det == ‘w’){myservo.write(90);delay(100);det = check();}

while (det == ‘U’){myservo.write(0);delay(100);det = check();}
while (det == ‘u’){myservo.write(90);delay(100);det = check();}

}

int check()
{if (Serial.available() > 0) {dataIn = Serial.read();
if (dataIn == ‘F’){determinant = ‘F’;}
else if (dataIn == ‘B’){determinant = ‘B’;}else if (dataIn == ‘L’){determinant = ‘L’;}
else if (dataIn == ‘R’){determinant = ‘R’;}else if (dataIn == ‘I’){determinant = ‘I’;}
else if (dataIn == ‘J’){determinant = ‘J’;}else if (dataIn == ‘G’){determinant = ‘G’;}
else if (dataIn == ‘H’){determinant = ‘H’;}else if (dataIn == ‘S’){determinant = ‘S’;}
else if (dataIn == ‘0’){vel = 0;}else if (dataIn == ‘1’){vel = 27.7;}
else if (dataIn == ‘2’){vel = 55.2;}else if (dataIn == ‘3’){vel = 83.1;}
else if (dataIn == ‘4’){vel = 110.4;}else if (dataIn == ‘5’){vel = 138.5;}
else if (dataIn == ‘6’){vel = 166.2;}else if (dataIn == ‘7’){vel = 193.9;}
else if (dataIn == ‘8’){vel = 221.6;}else if (dataIn == ‘9’){vel = 250;}
else if (dataIn == ‘q’){vel = 0;}
else if (dataIn == ‘U’){determinant = ‘U’;}else if (dataIn == ‘u’){determinant = ‘u’;}
else if (dataIn == ‘W’){determinant = ‘W’;}else if (dataIn == ‘w’){determinant = ‘w’;}

}return determinant;}

For range conversion the map() function is really useful. Look it up in Reference https://www.arduino.cc/reference/en/language/functions/math/map/

Something like map(joystickInput, 0, 1023, -255, 255) should get you close.

Steve

Hi, Welcome to the forum.

Please read the first post in any forum entitled how to use this forum. http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code. It will be formatted in a scrolling window that makes it easier to read.

Thanks.. Tom.... :)

thanks steve! ill check that out!