Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void readXYZ(int16_t *x_val, int16_t *y_val, int16_t *z_val){
- uint8_t x0 = 0;
- uint16_t x1 = 0;
- uint8_t y0 = 0;
- uint16_t y1 = 0;
- uint8_t z0 = 0;
- uint16_t z1 = 0;
- int16_t x = 0;
- int16_t y = 0;
- int16_t z = 0;
- //read X-Axis
- x0 = readRegister(0x80 | 0x32);
- x1 = readRegister(0x80 | 0x33);
- //read Y-Axis
- y0 = readRegister(0x80 | 0x34);
- y1 = readRegister(0x80 | 0x35);
- //read Z-Axis
- z0 = readRegister(0x80 | 0x36);
- z1 = readRegister(0x80 | 0x37);
- //convert in milli-G [4.0mg/LSB] in +/- 16g mode @ full-res
- x = (int16_t)((x1 << 8) | x0);
- y = (int16_t)((y1 << 8) | y0);
- z = (int16_t)((z1 << 8) | z0);
- *x_val = x * 4;
- *y_val = y * 4;
- *z_val = z * 4;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement