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.
Revision 3:faddd5d3218c, committed 2019-05-09
- Comitter:
- AliAlBadra
- Date:
- Thu May 09 04:31:51 2019 +0000
- Parent:
- 2:1a98f69712e8
- Commit message:
- Added Acc to gamepad;
Changed in this revision
FXOS8700CQ.cpp | Show annotated file Show diff for this revision Revisions of this file |
FXOS8700CQ.h | Show annotated file Show diff for this revision Revisions of this file |
--- 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];
--- a/FXOS8700CQ.h Mon Feb 06 08:41:24 2017 +0000 +++ b/FXOS8700CQ.h Thu May 09 04:31:51 2019 +0000 @@ -73,7 +73,9 @@ ~FXOS8700CQ(); void init(); Data get_values(); - + float get_pitch_angle(); + float get_roll_angle(); + private: I2C* i2c;