# Button programming

When we program a button to operate a motor they run smoothly in one direction but very choppy in the other, but when we change it to a joystick control it runs smoothly in both directions. How do we fix this.

If I had to guess you code is defining a motor to 0 and to -127 constantly over and over.

This would be cause by code like

if(up==1){
motor=127
}
if(up==0){
motor=0
}
if(down==1){
motor=-127
}

Please post your code and I can take a look at what is actually going wrong.
Do you use robotc or easyc?

Here it is. Thank for the help in advanced.
Compitition.c (1.66 KB)

Lets take a look at a “endeffector” part of your code. What happens when you press Btn5U? I’ll bold what your code executes.

When you press your buttons, your rapidly setting them on and off again, hence the “choppy” nature you were talking about before. Try something along these lines:

Now when you press a button, you’re only updating your motor values once. Apply this concept for the rest of your buttons and that should fix your problem. Hope that helps!

``````
if(vexRT[Btn6D]==1)
{
motor[rightlift]= 127;
motor[leftlift]= 127;
}
else
{
motor[rightlift]= 0;
motor[leftlift]=0;
}

if (vexRT[Btn6U]==1)
{
motor[rightlift]= -127;
motor[leftlift]= -127;
}
else
{
motor[rightlift]= 0;
motor[leftlift]=0;
}``````

Basically if you have 6D pressed but not 6U, then it’s going to set the motors to 127:

``````if(vexRT[Btn6D]==1)
{
motor[rightlift]= 127;
motor[leftlift]= 127;
}
else
{
motor[rightlift]= 0;
motor[leftlift]=0;
}``````

However, immediately afterward, you are setting them to 0 because 6U is not pressed:

``````if (vexRT[Btn6U]==1)
{
motor[rightlift]= -127;
motor[leftlift]= -127;
}
else
{
motor[rightlift]= 0;
motor[leftlift]=0;
}``````

This is why you’re getting the jitter. You are going back and forth from 127 to 0. You should make the whole thing into one block like this:

``````if(vexRT[Btn6D]==1)
{
motor[rightlift]= 127;
motor[leftlift]= 127;
}
else if (vexRT[Btn6U]==1)
{
motor[rightlift]= -127;
motor[leftlift]= -127;
}
else
{
motor[rightlift]= 0;
motor[leftlift]=0;
}``````

That way the motors are running forward if 6D is pressed, backward for 6U, or they do nothing if neither is pressed.

**Edit: **UnforeseenGamer beat me to it. Same minute too

Thanks everyone!! It works like a charm