There isn’t a good way to have the gyro value accumulate because just checking if the value jumped from round 360 to 0 could result in the value being off if the robot turns too fast. Since you said that you need to…

I would assume that you would need an error angle of how much to turn to get to the a target angle. This isn’t exactly what you asked for, but I think it would work better in this situation…

### Easy to understand way

```
double targetAngle;
double errorAngle;
while(true)
{
double gyroValue = gyro.get_value() / 10;
errorAngle = targetAngle - gyroValue;
while(errorAngle > 180) errorAngle -= 360;
while(errorAngle < -180) errorAngle += 360;
pros::delay(7);
}
```

Simply subtracting the current position from the target position will give you the angle you need to turn. This however is sometimes not the most optimal angle. We know that no angle is more than half a rotation way so the program checks to make sure and if it isn’t it adds or subtracts 360. This will result in the shortest angle (positive is one way, negative is the other). This will cover the issue of gyro values going from 360 to 0 and even let you set `targetAngle`

to angles greater than 360 or less than 0.

We can also shorten the code and make it more efficient…

### Slightly more efficient way

```
double targetAngle;
double errorAngle;
while(true)
{
double gyroValue = gyro.get_value() / 10;
errorAngle = targetAngle - gyroValue;
errorAngle += std::round(-errorAngle / 360.0) * 360.0;
pros::delay(7);
}
```