-
• #2
Got it.
-
• #3
Puck.accelOn();
Puck.on('accel', function(data) {
console.log(data.acc.x);
});
-
• #4
But I have another question.
Any idea how I can get x/y starting at 0 with a non sensitive movement tracking?
The raw values changing very fast.I would like to use the Puck.js as a Joystick.
Best regards
-
• #5
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)
-
• #6
Awesome, thank you Gordon!
Hi,
I saw the documentation about the built in accelerometer/gyroscope.
How I can return only the x/y values of the accelermoter, starting at 0?
Best regards