Go Down

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

##### Apr 18, 2019, 01:33 am
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

#1
##### Apr 18, 2019, 09:59 am
Something like ?

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

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

#### Mampfi

#2
##### Apr 18, 2019, 07:44 pm
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