Counting Radians

I have an object that rotates based on the mouse position
and I’m trying to count the degrees as it rotates.
for example if i rotate 200 degrees cww the degree measurement is 200
if i will rotate another 350 degrees cww the degree measurement will be 550
now if i rotate 150 cw the measurement will be 400 now.

I have this code: (it counts radians, but it is the same idea)
p1 = mouse position

   
             theX = p1.x - 250;
             theY = p1.y - 250;
             radian = -Math.atan2(theY, theX);
             if (mouseY <= 250)
            {
                total_radian += Math.abs(radian) - old_radian;
            }
            else if (mouseY >= 250)
            {
                total_radian += old_radian - Math.abs(radian);
             }

the problem is that if i rotate quickly it will miscalculate it.
any suggestions for better counting?