Aaron Berk
/
ADXL345_HelloWorld
ADXL345 triple axis, digital accelerometer example.
Revision 0:9e92575dece6, committed 2010-08-03
- Comitter:
- aberk
- Date:
- Tue Aug 03 08:31:00 2010 +0000
- Commit message:
- Version 1.0
Changed in this revision
diff -r 000000000000 -r 9e92575dece6 ADXL345_lib.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ADXL345_lib.lib Tue Aug 03 08:31:00 2010 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/aberk/programs/ADXL345_lib/latest \ No newline at end of file
diff -r 000000000000 -r 9e92575dece6 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue Aug 03 08:31:00 2010 +0000 @@ -0,0 +1,36 @@ +#include "ADXL345.h" + +ADXL345 accelerometer(p5, p6, p7, p8); +Serial pc(USBTX, USBRX); + +int main() { + + int readings[3] = {0, 0, 0}; + + pc.printf("Starting ADXL345 test...\n"); + pc.printf("Device ID is: 0x%02x\n", accelerometer.getDevId()); + + //Go into standby mode to configure the device. + accelerometer.setPowerControl(0x00); + + //Full resolution, +/-16g, 4mg/LSB. + accelerometer.setDataFormatControl(0x0B); + + //3.2kHz data rate. + accelerometer.setDataRate(ADXL345_3200HZ); + + //Measurement mode. + accelerometer.setPowerControl(0x08); + + while (1) { + + wait(0.1); + + accelerometer.getOutput(readings); + + //13-bit, sign extended values. + pc.printf("%i, %i, %i\n", (int16_t)readings[0], (int16_t)readings[1], (int16_t)readings[2]); + + } + +}
diff -r 000000000000 -r 9e92575dece6 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Tue Aug 03 08:31:00 2010 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/9114680c05da