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.
Diff: FXOS8700CQ.cpp
- Revision:
- 3:faddd5d3218c
- Parent:
- 0:f66eda6a492a
--- a/FXOS8700CQ.cpp Mon Feb 06 08:41:24 2017 +0000 +++ b/FXOS8700CQ.cpp Thu May 09 04:31:51 2019 +0000 @@ -8,7 +8,7 @@ */ #include "FXOS8700CQ.h" - +#include <cmath> // constructor is called when the object is created - use it to set pins and frequency FXOS8700CQ::FXOS8700CQ(PinName sda, PinName scl) { @@ -116,6 +116,22 @@ return values; } +float FXOS8700CQ::get_pitch_angle(){ + Data values = get_values(); + float numerator = -1 * values.ax ; + float squared_den = (values.ay * values.ay) + (values.az * values.az); + float denomenator = sqrt(squared_den); + float pitch_angle_radians = atan2(numerator , denomenator); + float pitch_angle_degrees = pitch_angle_radians * (180 / 3.14159); + return pitch_angle_degrees; + } +float FXOS8700CQ::get_roll_angle(){ + Data values = get_values(); + float roll_angle_radians = atan2(values.ay , values.az); + float roll_angle_degrees = roll_angle_radians * (180 / 3.14159); + return roll_angle_degrees; + } + void FXOS8700CQ::send_byte_to_reg(char byte,char reg) { char data[2];