# Problem coding a drivetrain

Rookie programmer here! So i wanted to code a 6 wheel drive train directly powered by 6 motors. I wanted to make one analog control vertical motion, and the other for turning. I’ve got two if statements for turning left and right, but the code only seems to execute whatever is 2nd in order…
Here’s what i have so far:

``````#include "main.h"
void operatorControl() {

while (1) {
delay(20);
int x = joystickGetAnalog(1,3);
int y = joystickGetAnalog(1,1);

if (y<-15){
motorSet(2,x);
motorSet(3,x);
motorSet(4,x);
motorSet(5,-y);
motorSet(6,-y);
motorSet(7,-y);
}
else {
motorSet(2,x);
motorSet(3,x);
motorSet(4,x);
motorSet(5,x);
motorSet(6,x);
motorSet(7,x);
}

if (y > 15){
motorSet(2,y);
motorSet(3,y);
motorSet(4,y);
motorSet(5,x);
motorSet(6,x);
motorSet(7,x);
}
else{
motorSet(2,x);
motorSet(3,x);
motorSet(4,x);
motorSet(5,x);
motorSet(6,x);
motorSet(7,x);
}
}
}

``````

I’ve tried switching the order of the if statements and the opposite would happen on the bot. Why is this happening and how can I get both sides of the drive to work?
Thanks!

The reason this is happening is because there are two else statements, one of which is always going to run, so even if the first if evaluates to true, the second one will evaluate to false and run what’s in the second else statement. What you want to do is use an else-if statements (not sure what they call it in EasyC), so your program is essentially like this:

``````if y < -15
Turn Left
else if y > 15
Turn Right
else
Go straight fwd/bwd
``````

Also, if you are using the left-right stick for turning and front-back stick for forward backward, you might want to change your x and y definitions so they are consistent with standard coordinate naming (i.e. Y on the vertical, X on the horizontal).

Ohhh that makes sense! Thanks a lot. Also, I’m using PROS not easyC
(thanks for the tip)