Arduino_Code_for_the_Remote:

void setup()
{
Serial.begin(9600);
digitalWrite(4, HIGH); pinMode(4, INPUT);
digitalWrite(5, HIGH); pinMode(5, INPUT);
}

unsigned int V1;
unsigned int L1;
long LEFT = 255;
long RIGHT = 255;
long Throttle; //forwards is positive, reverse is negative
long Percent; //percentage of power given to the right side

void loop()
{

///////////////////////////////////////////////////////////////
//Read JOY Position
///////////////////////////////////////////////////////////////
L1 = analogRead(5);//Joy latteral read analog value (1023 is the most left position and 0 is the most right position
V1 = analogRead(4);//Joy vertical read analog value (1023 is the most up/forward position and 0 is the most down/reverse position)

Percent = L1 + 1; //add 1 so I never have to divide by zero 0
Percent = Percent * 100; //scale up the value to apply a ratio to the “RIGHT” and “LEFT”
Percent = (Percent/1024); //divide by the most possible value (all the way right)

///////////////////////////////////////////////////////////////
//TEST JOY Position and calculate respective direction
///////////////////////////////////////////////////////////////

if (V1>600 & Percent<60 & Percent>40)//Forward
{
RIGHT = 255;
LEFT = 255;
}
else if (V1>600 & Percent<96 & Percent>59)//Forward but left
{
RIGHT = 255;
LEFT = (150-Percent)255;
LEFT = LEFT/100;
}
else if (V1>600 & Percent<41 & Percent>4)//Forward but right
{
RIGHT = (Percent+50)
255;
RIGHT = RIGHT/100;
LEFT = 255;
}
else if (V1<400 & Percent<60 & Percent>40)//Reverse
{
RIGHT = -255;
LEFT = -255;
}
else if (V1<400 & Percent<96 & Percent>59)//Reverse but left
{
RIGHT = -255;
LEFT = (150-Percent);
LEFT = LEFT/100;
}
else if (V1<400 & Percent<41 & Percent>4)//Reverse but right
{
RIGHT = (Percent+50)
(-255);
RIGHT = RIGHT/100;
LEFT = -255;
}
else if (V1>399 & V1<601 & Percent>80)//Sharp left turn
{
RIGHT = +255;
LEFT = -255;
}
else if (V1>399 & V1<601 & Percent<20)//Sharp right turn
{
RIGHT = -255;
LEFT = +255;
}
else //stop
{
RIGHT = 0;
LEFT = 0;
}


// Remote Arduino Serial Port ->
//Remote Xbee Shield ->
//Tank Xbee Shield ->
//Tank Arduino ->
//TankShield pin 12, 13

// command structure is:
//”THROTTLE|left-gear-box|right-gear-box;”
Serial.print(“THROTTLE|”); //print the throttle command to the serial port
Serial.print(RIGHT);
Serial.print(”|”);
Serial.print(LEFT);
Serial.print(”;”);

delay(100);//give time for the XBee transfer
}




Edit History