FXOS8700CQ class modified for el17yfk
Diff: FXOS8700CQ.cpp
- Revision:
- 3:eedcae2bd4aa
- Parent:
- 0:f66eda6a492a
- Child:
- 4:5a6ef0d027c4
--- a/FXOS8700CQ.cpp Mon Feb 06 08:41:24 2017 +0000 +++ b/FXOS8700CQ.cpp Wed Apr 17 17:53:33 2019 +0000 @@ -8,6 +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) @@ -159,4 +160,20 @@ if (nack) error("No acknowledgement received!"); // if we don't receive acknowledgement, send error message +} + +float FXOS8700CQ::get_pitch_angle() +{ + Data values = get_values(); + float pitch_angle = atan2(-values.ax,sqrt(values.ay*values.ay + values.az*values.az))*180.0/3.1416; + + return pitch_angle; +} + +float FXOS8700CQ::get_roll_angle() +{ + Data values = get_values(); + float roll_angle = atan2(values.ay,values.az)*180.0/3.1416; + + return roll_angle; } \ No newline at end of file