Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: BLE_API mbed-dev-bin nRF51822
Fork of microbit-dal by
Diff: source/drivers/MicroBitAccelerometer.cpp
- Revision:
- 43:0374ea4d2167
- Parent:
- 42:e2869e0fa366
- Child:
- 55:6920de8ba10a
--- 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;
}
