Using CMDeviceMotion to get total angle rotated

92 Views Asked by At

I am trying to create an app that can calculate the number of times a phone is spun on a finger like a basketball. I have been using DeviceMotion to get the attitude, and I manipulated the data so instead of it going from 1 to 179 then back on the negative side it goes 0-360. But I can not seem to add to a totalRotation variable after it goes around the 0 mark.

Simple terms, I want to have two variables, one is the current yaw which should be in degrees and between 0 and 360. The other is a total which should continue to add as the phone rotates. So after 1.5 rotations, the current yaw should read 180, and the total should read 540. Is there an easy way to do this?

0

There are 0 best solutions below