How to Modified the Compass readings

How to change the readings from a compass to ,

North,
South
West
and East.

Please advice

You can read the angle value and if is in the certain range you can treat it as a North or any other direction you want.

Edit:

Something like:

N: 337.5 <= angle < 22.5
NE: 22.5 <= angle < 67.5
E: 67.5 <= angle < 112.5

@ Architect - Do you have a complete code for this ?

No, but it is really simple. Something like this:

        public static string GetDirection(double angle)
        {
            if (angle >= 337.5 || angle < 22.5)
                return "N";
            else if (angle >= 22.5 && angle < 67.5)
                return "NE";
            else if (angle >= 67.5 && angle < 112.5)
                return "E";
            else if (angle >= 112.5 && angle < 157.5)
                return "SE";
            else if (angle >= 157.5 && angle < 202.5)
                return "S";
            else if (angle >= 202.5 && angle < 247.5)
                return "SW";
            else if (angle >= 247.5 && angle < 292.5)
                return "W";
            else 
                return "NW";

        }

You have to check what angle value is N for your compass. The function above is for 0(360) being North. If compass returns different angle for North then you just need to rotate return values accordingly.

@ Architect - does that first line work?

Should be or not and?

@ Justin - Thanks for proofing! You are right the first one should be OR. I will modify it.

@ Architect - your most welcome, its usually me needing the proofing :slight_smile:

Updated the code.