Library for accelerometer KXR94-2050
KXR94_2050.cpp
- Committer:
- 66keg
- Date:
- 2015-01-03
- Revision:
- 0:2700ada3a245
- Child:
- 2:1e4a75b43643
File content as of revision 0:2700ada3a245:
#include "KXR94_2050.h" KXR94_2050::KXR94_2050(PinName OutX, PinName OutY, PinName OutZ) : _OutX(OutX), _OutY(OutY), _OutZ(OutZ) { X_ZERO_VAL = 2097; Y_ZERO_VAL = 2050; Z_ZERO_VAL = 2052; } void KXR94_2050::gsetZeroVal(uint16_t x_zero, uint16_t y_zero, uint16_t z_zero) { X_ZERO_VAL = x_zero; Y_ZERO_VAL = y_zero; Z_ZERO_VAL = z_zero; } void KXR94_2050::getRawData(float &pitch, float &roll) { uint16_t Xacc = X_value.read_u16(); uint16_t Yacc = Y_value.read_u16(); uint16_t Zacc = Z_value.read_u16(); int xval = Xacc - X_ZERO_VAL; int yval = Yacc - Y_ZERO_VAL; int zval = Zacc - Z_ZERO_VAL; roll = atan2l(yval, zval) * 180.0 / PI; pitch = atan2l(xval, zval) * 180.0 / PI; }