You are reading a single comment by @Gordon and its replies. Click here to read the full conversation.
  • Hi - there's a bit of info on: http://www.espruino.com/Reference#l_PuckĀ­_accel

    Basically acc.x/y/z are the values off the chip, which will be the acceleration in G's multiplied by 8192 (unless you've configured the chip for something else - see below).

    If you run this code with the Puck.js flat on the table, you should expect x and y to be pretty much 0, and z to be around 8192 (1g).

    Puck.on('accel',print);
    Puck.accelOn();
    

    However in your example you're detecting movement. This configures the accelerometer to sit there looking at x/y/z values to see if they vary by a lot, and to then flag up any movement. The acceleration reported is just the current acceleration at the time movement is reported, so if you're moving slow it's more or less the angle of the Puck, but if you're moving fast it's not really a useful value.

    One thing to add here is puckjsv2-accel-movement configures the accelerometer in the 2g mode (default is 4g) so now the acceleration figures need to be divided by 16384 to get Gs.

    So basically require("puckjsv2-accel-movement") won't give you one instantaneous value that shows you how much the device has moved. You'll need to look at several of the reported Puck.on('accel' events and see the difference between them.

About

Avatar for Gordon @Gordon started