var avr = Puck.mag();
var magDiff;
var movementCounter = 0;
var magCounter = 0;
Puck.on('mag', function(xyz) {
// work out difference in field
var dx = xyz.x-avr.x;
var dy = xyz.y-avr.y;
var dz = xyz.z-avr.z;
magDiff = Math.sqrt(dx*dx+dy*dy+dz*dz);
// update average
avr.x += dx/2;
avr.y += dy/2;
avr.z += dz/2;
magCounter++;
if (magDiff > 50) movementCounter++;
});
Puck.magOn();
setInterval(function(){
var movement = movementCounter / magCounter;
movementCounter = 0;
magCounter = 0;
Bluetooth.println(movement);
}, 60000 /* update every minute */);
But you then need to remove the whole connection.write("reset();\n", function() { .... part from the Web Bluetooth example.
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.
Something like this:
But you then need to remove the whole
connection.write("reset();\n", function() { ....
part from the Web Bluetooth example.