I put together a simple color-coded compass using the Puck's magnetometer. It's admittedly less robust and doesn't contain much sophisticated math, but it more or less matches readings from my smartphone's compass app. See attached file.
Red, Green, Blue Sequential Flash = North (330 to 30 deg)
Solid Red = East (60 to 120 deg)
Solid Green = South (150 to 210 deg)
Solid Blue = West (240 to 300 deg)
- Turn compass on/off via button click
- Fade color in/out between cardinal directions. For example, when pointing to 135 deg, both Red and Green LEDs should be lit. As directions moves more toward 90 degrees, Red gets stronger and Green gets weaker. Or at least something similar to indicate intermediate directions.
See this thread for more sophistication: http://forum.espruino.com/conversations/297915/