This is a functioning Arduino sketch using the tinySheild 21 Led segment and TinySheild 3-axis Compass model# ASD2613 with a Tinyduino. The LED tinysheild reamins pointing North as your rotate the unit.
Note, calibration is required with each use. Monitor the serial port and drections will be provided. (Basically, you just spin it approximately 3-5 turns on each axis. The device will work stand-alone or attached via serial connection. If attached using the serial port then formatted data is delivered thru the connection for the curious.
The sketch illuminates the led segment that has a 0 degree heading. The led heading north is illuminated as the tinyduino is rotated about its axis. I am presently working to refine the code and comment.
Options exist for selecting true or magnetic North. Also, if you are a stickler for accuracy, then you need to adjust for your magnetic declination.
This is a work in progress and portions of the code were borrowed from more talented others!
The tinysheild Compass uses a HMC5883L providing 1-2 degree resolution.
The 21 led tinysheild Model 2412 can either be Charlieplexed or addressed individually. In this sketch I did not use Charlieplexing.