Using PID code different from its mathematics equation
My answer to Understanding the flow of a PI controller may be useful (or not!). In it I give a simplistic example of PI control for a car's cruise control.
I don't like the sample code comment &quot;The integral part should only act if we are close to the desired position but we want to fine tune the error.&quot; Here's why:

Figure 3. The classic PID control function. Source: Wikipedia - PID controller.

The classic PID control function has no if statement in it. The integrator, if implemented, is running continuously from power-up.
As explained in my linked answer, P-only control will never reach the target (unless there is overshoot) and will settle down with an offset. In your implementation, if the offset is greater than your ±3° then your integral control will never turn on and the offset will never be eliminated.

As pointed out in the linked answer, when the integral action zeros the error the contribution of the proportional action is zero and the output depends only on the integral action.