My fork
Dependencies: BLE_API nRF51822-bluetooth-mdw
Fork of microbit-dal by
Diff: source/drivers/MicroBitAccelerometer.cpp
- Revision:
- 43:0374ea4d2167
- Parent:
- 42:e2869e0fa366
- Child:
- 55:6920de8ba10a
diff -r e2869e0fa366 -r 0374ea4d2167 source/drivers/MicroBitAccelerometer.cpp --- a/source/drivers/MicroBitAccelerometer.cpp Wed Jul 13 12:18:22 2016 +0100 +++ b/source/drivers/MicroBitAccelerometer.cpp Wed Jul 13 12:18:23 2016 +0100 @@ -666,13 +666,13 @@ */ void MicroBitAccelerometer::recalculatePitchRoll() { - float x = (float) getX(NORTH_EAST_DOWN); - float y = (float) getY(NORTH_EAST_DOWN); - float z = (float) getZ(NORTH_EAST_DOWN); + double x = (double) getX(NORTH_EAST_DOWN); + double y = (double) getY(NORTH_EAST_DOWN); + double z = (double) getZ(NORTH_EAST_DOWN); - roll = atan2((double)getY(NORTH_EAST_DOWN), (double)getZ(NORTH_EAST_DOWN)); + roll = atan2(y, z); + pitch = atan(-x / (y*sin(roll) + z*cos(roll))); - pitch = atan(-x / (y*sin(roll) + z*cos(roll))); status |= MICROBIT_ACCEL_PITCH_ROLL_VALID; }