Skip to content

Instantly share code, notes, and snippets.

@ss23
Created November 15, 2014 12:37
Show Gist options
  • Save ss23/4259b2bfb00d398b1860 to your computer and use it in GitHub Desktop.
Save ss23/4259b2bfb00d398b1860 to your computer and use it in GitHub Desktop.
void getAccelerometerData(int16_t * result) {
//int regAddress = 0x32; //first axis-acceleration-data register on the ADXL345
int regAddress = 0x30; // One before the first, to see if we were just off by two bytes
byte buff[A_TO_READ];
readFrom(ACC, regAddress, A_TO_READ, buff); //read the acceleration data from the ADXL345
//each axis reading comes in 10 bit resolution, ie 2 bytes. Least Significat Byte first!!
//thus we are converting both bytes in to one int
result[0] = (((int)buff[1]) << 8) | buff[0];
result[1] = (((int)buff[3])<< 8) | buff[2];
result[2] = (((int)buff[5]) << 8) | buff[4];
result[3] = (((int)buff[6]) << 8) | buff[7];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment