Micro:Bit Acceleration Video – Behind the MakeCode Hardware
Forces in space
Since we don’t live on a flat world, forces happen in three dimensional space. If the movement of an object isn’t exactly in the direction of one axis, we need a way to calculate its acceleration from the values measured for all the axes together.
If you put your micro:bit on a level table and push it diagonally, you have an acceleration in two dimensions. You can find the acceleration in that direction just like how you calculate the long side of a triangle using the two shorter sides (X and Y):
strength2D = Math.sqrt((accelX * accelX) + (accelY * accelY))
If you decide to lift your micro:bit off the table, then you’ve just added another dimension, so insert the acceleration value for the Z axis into the equation:
strength3D = Math.sqrt((accelX * accelX) + (accelY * accelY) + (accelZ * accelZ))