WebbotLib AVR library
WebbotLib It just does it
  C++ documentation  C documentation

ADXL345 3 Axis Accelerometer

The ADXL345 is a 3 axis accelerometer from Analog Devices capable of measuring ±16g.
Data sheet: http://www.sparkfun.com/datasheets/Sensors/Accelerometer/ADXL345.pdf
This library supports the device using I2C so pin 7 (CS) should be connected to pin 1 (Vdd) and pin 12 (SDO) can be used to select the I2C address. If pin 12 is connected to ground then the I2C address is 0xA6 and if pin 12 is connected to Vdd then the address is 0x3A. Project Designer will show you how to connect the pins.
Assuming you have called the device 'myAccel' in Project Designer then add the following code to your 'appControl' function:-
// Read the accelerometer and store results
// Retrieve the x axis value in mG
ACCEL_TYPE x = myAccel.getX();
// Retrieve the x axis value in mG
ACCEL_TYPE y = myAccel.getY();
// Retrieve the x axis value in mG
ACCEL_TYPE z = myAccel.getZ();
// Each value can be printed to stdout:
cout << "X=" << x << " Y=" << y << " Z=" << z;
// or all values can be dumped to stdout out using
cout << myAccel;
The values returned are in 'mG' ie 1000ths of the gravitational constant.
Function Summary

Valid XHTML 1.0 Transitional