However compass could be ok as long as there are no magnets floating around (or you could ensure you mount the Puck with a magnet nearby so that you're then measuring the rotation relative to that magnet). You just need to rotate the Puck a full 360 degrees when you start up so you can calibrate the max/minimum values.
This is some old code I had kicking around that that works out an angle then lights up accordingly. Realistically to work nicely it needs a magnet nearby though
var Vec3 = require("Vec3");
var vmin = new Vec3(Puck.mag());
var vmax = vmin;
function onMag(xyz) {
vmin = vmin.min(xyz);
vmax = vmax.max(xyz);
var c = vmin.add(vmax).mul(0.5).sub(xyz);
var a = Math.atan2(c.x,c.y)*180/Math.PI;
analogWrite(LED1,a/180,{freq:100,soft:true});
analogWrite(LED2,-a/180,{freq:100,soft:true});
}
Puck.on('mag', onMag);
Puck.magOn(10);
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
As mentioned, gyro would work well.
However compass could be ok as long as there are no magnets floating around (or you could ensure you mount the Puck with a magnet nearby so that you're then measuring the rotation relative to that magnet). You just need to rotate the Puck a full 360 degrees when you start up so you can calibrate the max/minimum values.
This is some old code I had kicking around that that works out an angle then lights up accordingly. Realistically to work nicely it needs a magnet nearby though