Go Down

Topic: Degrees mapping 360deg formulas (Read 96 times) previous topic - next topic

slad1995

Hi all,

Im working on a project but cant seam to cum up with a solution to a issue im having.



im using poxzy sensor and from the imu i can get the orientation of the sensor but im having an issue with it would be reading 130 deg when i want to 90 to be read

so it would be easy reading_angle-40= 90 deg

but say if the reading_angle = 30 deg

my formula would be reading 30-40 = -10 deg

but i don't want to measure -10 deg i want 350 deg


anyone have a formula that i could use or any idea how i would solve this issue?

Thanks

Robin2

Something like ?

Code: [Select]
if (degreeVal < 0) {
   degreeVal += 360;
}


...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Mampfi

There is a Function in the Arduino Core called map wich could do this, take a look here: https://www.arduino.cc/reference/en/language/functions/math/map/

Go Up