Cardinal is an Arduino library that takes input in degrees and output a string or integer for the 4, 8, 16, or 32 compass headings (like North, South, East, and West). It also makes available environment variables for the minimum, maximum, and middle azimuth of all of the 32 directions. It works fantastically when paired with a magnetometer.
Cardinal is currently compatible with both Arduino 1.0.x and 1.5.x.
Cardinal is in the library manager. From the latest version of the Arduino IDE, go to Sketch > Tools > Include Library > Manage Libraries
and search and install the latest release version of Cardinal.
Download the latest release ZIP from here or the latest testing version from here. Then go to Sketch > Tools > Include Library > Add ZIP Library
.
The first thing to do is to include the library in your sketch. Goes to Sketch > Include Library > Cardinal
. The example has everything put to use in it, so I would advice looking there too. You should also take a look at the types at the wiki page here.
This initializes the class and bind it to a name of your choosing. Just use cardinal
and make it simple. You will call the other functions with like name.otherFunction
. So, if you choose cardinal, then it would be cardinal.otherFunction
.
Example:
Cardinal cardinal;
This will take the type that you select and an input float in degrees and about a heading by numbers 1 through 32.
Example:
cardinal.getInteger(3, 190.15);
// returns 18
This will take the type that you select and an input float in degrees and about a heading in text format.
Example:
cardinal.getString(3, 190.15);
// returns SbW
Environment Variables for the integer id, middle azimuth, minimum degrees, and maximum degrees for all 32 headings are available here.
I found the rainbow compass image and the table of headings on this Wikipedia page very helpful in understand these directions.