Hi - it depends on the code you're using. For example in http://www.espruino.com/Puck.js+Door+Light we have:
var zero = Puck.mag(); var doorOpen = false; function onMag(p) { p.x -= zero.x; p.y -= zero.y; p.z -= zero.z; var s = Math.sqrt(p.x*p.x + p.y*p.y + p.z*p.z); var open = s<1000; if (open!=doorOpen) { doorOpen = open; digitalPulse(open ? LED1 : LED2, 1,1000); } } Puck.on('mag', onMag); Puck.magOn();
The magic bit there is zero = Puck.mag();. Just call var zero = Puck.mag(); again and it'll reset the zero value to the current magnetometer reading.
zero = Puck.mag();
zero
@Gordon started
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.
Hi - it depends on the code you're using. For example in http://www.espruino.com/Puck.js+Door+Light we have:
The magic bit there is
zero = Puck.mag();
. Just call varzero = Puck.mag();
again and it'll reset thezero
value to the current magnetometer reading.