base program for tilt measurement
Dependencies: COG4050_ADT7420 ADXL362
Fork of COG4050_adxl355_adxl357-ver2 by
Diff: ADXL35x/ADXL355.cpp
- Revision:
- 10:f5ba762b58b4
- Parent:
- 8:9e6ead2ee8d7
diff -r 6c803986dbde -r f5ba762b58b4 ADXL35x/ADXL355.cpp --- a/ADXL35x/ADXL355.cpp Mon Sep 03 10:39:56 2018 +0000 +++ b/ADXL35x/ADXL355.cpp Fri Sep 07 15:50:53 2018 +0000 @@ -81,7 +81,7 @@ adxl355.write((reg<<1) | _READ_REG_CMD); ret_val = 0x0f & adxl355.write(_DUMMY_BYTE); ret_val = (ret_val<<8) | adxl355.write(_DUMMY_BYTE); - ret_val = (ret_val<<8) | adxl355.write(_DUMMY_BYTE); + ret_val = (ret_val<<4) | (adxl355.write(_DUMMY_BYTE)>>4); cs = true; return ret_val; } @@ -233,4 +233,40 @@ //uint32_t rawValue = data<<(32-nbit); // Otherwise perform the 2's complement math on the value return float((~(data - 0x01)) & 0xfffff) * -1; -} \ No newline at end of file +} + +/** ----------------------------------- */ +/** ANGLE MEASUREMENT */ +/** ----------------------------------- */ +//single axis +float ADXL355::single_axis(float x) + { + float Y; + //int a=4; + Y = floor(asin(x)*100)/100; + //void arm_cmplx_mag_f32 (double *Y, double *X, int32_t a); + + Y = floor(((57.2957f)*(Y))*100)/100; + return Y; + + } + +//Dual Axis +float ADXL355::dual_axis(float x, float y) + { + float Y; + Y = 57.2957f * (atan(x/y)); + Y = floor(Y*100)/100; + return Y; + } + +//Triaxial +float ADXL355::tri_axis(float x, float y, float z) + { + float Y; + float X; + X = (x)/(sqrt((y*y)+(z*z))); + Y= atan(X); + Y = floor(Y*57.2957*100)/100; + return Y; + }