We have tried to use sensors in our autonomous to no avail, and our state tournament is in 2 days. The major trouble makers are our potentiometer on the arm and the gyro for turning. The gyro, even though I have not adjusted the sensor scale, still gives random values for the same turn, and turns differently every time for a given turning value. The potentiometer moves constantly, changing the upper and lower limits, so the code always freaks out, and sometimes the pot sends random values, causing the arm to either go all the way up or stop somewhere on the way to the expected value. Is there any way I could make these more consistent when it comes to the values they send to the cortex?

Pot code for the arm:

```
void armcontrol(int speed1, int height,int speed2)/*This function raises or lowers the arm to a certain point.
It's used by specifying a speed at which to raise and a height (potentiometer value) at which to stop raising.
The speed2 variable is a speed to back up at while lifting- We have this because we have a nonlinear lift, which
needs to back up while lifting in order to pick up skyrise pieces properly.*/
{
clearTimer(T2);
bool raising = true;
int prevalue = 3300;
if(speed1 > 0)//Checks which direction to move the arm. Positive is up, negative is down.
{
clear();//Clears values: left over from when we used encoders for the lift.
while(raising)//Sets motor values while the condition (or height) is not the specified value.
{
if(time1(T2) == 200)
{
prevalue =SensorValue[armencoderR];
clearTimer(T2);
}
motor[armleft1] = speed1;
motor[armright1] = speed1;
motor[armleft2] = speed1;
motor[armright2] = speed1;
motor[frontleft] = -speed2;
motor[backleft] = -speed2;
motor[backright] = -speed2;
motor[frontright] = -speed2;
if(abs(SensorValue[armencoderR] - prevalue) > 600)
{
continue;
}
else if(SensorValue[armencoderR] >3500 || SensorValue[armencoderR] <1560)//These are the upper and lower limits for the arm. The higher the value, the lower the arm is.
{
break;
}
else if(SensorValue[armencoderR] <= height)
{
raising = false;
}
}
stopbase();
motor[armleft1] = 0;
motor[armright1] = 0;
motor[armleft2] =0;
motor[armright2] = 0;
}
else if(speed1 < 0)
{
clear();
while(raising)
{
if(time1(T2) == 200)
{
prevalue =SensorValue[armencoderR];
}
motor[armleft1] = speed1;
motor[armright1] = speed1;
motor[armleft2] = speed1;
motor[armright2] = speed1;
motor[frontleft] = -speed2;
motor[backleft] = -speed2;
motor[backright] = -speed2;
motor[frontright] = -speed2;
if(abs(SensorValue[armencoderR] - prevalue) > 600)
{
continue;
}
else if(SensorValue[armencoderR] >3500 || SensorValue[armencoderR] <1560)
{
break;
}
else if(SensorValue[armencoderR] >= height)
{
raising = false;
}
}
stopbase();
motor[armleft1] = 0;
motor[armright1] = 0;
motor[armleft2] = 0;
motor[armright2] = 0;
}
}
```

Gyro code for turns

```
void turnright(int speed, int degrees)/*These two functions turn the robot based on a gyro value.
They turn then stop the robot.*/
{
clear();
while(SensorValue[gyro] > -degrees)
{
motor[frontright] = speed;
motor[backright] = -speed;
motor[backleft] = speed;
motor[frontleft] = -speed;
}
stopbase();
}
```

here is the clear() function referenced several times:

```
void clear()
{
SensorValue[gyro] = 0;
SensorValue[intakeencoder] = 0;
}
```

Any help would be appreciated.