Aerial Tram prototype model

We have a project where we must build a scale model of a ski lift. My group decided to use an arduino uno with 2 ultrasonic sensors, and a DVR8833 motor controller connected to a single motor.

Any thoughts on the program below?

//Ultrasonic Controls - 4 ultrasonic sensors
const int trigPin1 = 2; //TRIG for sensor 1 pin to digital pin 2
const int echoPin1 = 3; //ECHO for sensor 1 pin to digital pin 3
const int trigPin2 = 4; //TRIG for sensor 2 pin to digital pin 4
const int echoPin2 = 5; //ECHO for sensor 2 pin to digital pin 5

//Values for distance
const int d1 = 30; //Max distance, in cm
const int d2 = 20; //Distance 2, in cm
const int d3 = 15; //Distance 3, in cm
const int d4 = 10; //Distance 4, in cm
const int d5 = 8; //Distance 5, in cm
const int d6 = 5; //Stopping distance

const int In1 = 12; //left motor top to digital pin 12
const int In2 = 13; //left motor bottom to digital pin 13

void setup()
{
Serial.begin(9600);

pinMode(In1, OUTPUT);
pinMode(In2, OUTPUT);

pinMode(trigPin1, OUTPUT);
pinMode(echoPin1, INPUT);
pinMode(trigPin2, OUTPUT);
pinMode(echoPin2, INPUT);
}

void loop()
{
int cm = 0;
ping(trigPin1, echoPin1, cm);
int ds1 = cm;
ping(trigPin2, echoPin2, cm);
int ds2 = cm;

int AA = In1;
int BB = In2;

if(ds1 > d1 && ds2 > d1)
{
Move(AA, BB, 100);
}
else if(ds1 <= d1 || ds2 <= d1)
{
Move(AA, BB, 75);
}
else if(ds1 <= d2 || ds2 <= d2)
{
Move(AA, BB, 50);
}
else if(ds1 <= d3 || ds2 <= d3)
{
Move(AA, BB, 30);
}
else if(ds1 <= d4 || ds2 <= d4)
{
Move(AA, BB, 25);
}
else if(ds1 <= d5 || ds2 <= d5)
{
Move(AA, BB, 10);
}
else if(ds1 <= d6 || ds2 <= d6)
{
Move(AA, BB, 0);
delay(3000);
Reverse(AA, BB);
Move(AA, BB, 10);
delay(5000);
Move(AA, BB, 25);
delay(3000);
}
}

void Move (int A, int B, int C)
{
analogWrite(A, C);
analogWrite(B, 0);
delay(1000);
return;
}

void Reverse (int A, int B)
{
int temp;
temp = A;
A = B;
B = temp;
return;
}

void ping(int A, int B, int C)
{
digitalWrite(A, LOW);
delayMicroseconds(2);
digitalWrite(A, HIGH);
delayMicroseconds(10);
digitalWrite(A, LOW);
int duration = pulseIn(B, HIGH);
C = duration / 29 / 2;
return;
}

Please put your code in its own window as seen in other posts. This can be done by placing     [code]  and [/code]  around the code or use the </> icon. This makes it easier for others to read.

How to use this forum

Please edit your post to put code in a code box.

"Any thoughts....." Does it work? What do you want us to comment on?

Weedpharma

instead of variables like A, B. aa, bb, ect, use descriptive names...

I agree with @Qdeathstar. After a week's holiday you won't have a clue how that program works.

The names of variables and functions are only used by the compiler. Long meaningful names have no effect on the size of the code uploaded to the Arduino.

Have a look at planning and implementing a program.

...R