To get the value from 0, you need to subtract a 'base' value.
For instance you could do:
Puck.accelOn();
var accZero = Puck.accel().acc; // get the base value when we start up
Puck.on('accel', function(data) {
console.log(data.acc.x - accZero.x);
});
If you want to stop the values moving so fast, you can do an average:
Puck.accelOn();
var accZero = Puck.accel().acc; // get the base value when we start up
var avrX = 0;
Puck.on('accel', function(data) {
avrX = (avrX*0.9) + 0.1*(data.acc.x - accZero.x);
console.log(avrX);
});
You can change values to get a slower movement but they must always add up to 1, so 0.9/0.1 or 0.8/0.2(faster) or 0.95/0.05(slower)
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.
To get the value from 0, you need to subtract a 'base' value.
For instance you could do:
If you want to stop the values moving so fast, you can do an average:
You can change values to get a slower movement but they must always add up to 1, so 0.9/0.1 or 0.8/0.2(faster) or 0.95/0.05(slower)