a

Dependencies:   ADXL345_I2C ITG3200 mbed

Fork of ADXL345 by James Allen

Committer:
jrha
Date:
Fri Mar 11 15:54:40 2011 +0000
Revision:
0:75c7bfd01ea0
Child:
1:67703f5eab67

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jrha 0:75c7bfd01ea0 1 #include "mbed.h"
jrha 0:75c7bfd01ea0 2 #include "ADXL345_I2C.h"
jrha 0:75c7bfd01ea0 3
jrha 0:75c7bfd01ea0 4 //ADXL345 accelerometer(p5, p6, p7, p8);
jrha 0:75c7bfd01ea0 5 ADXL345_I2C accelerometer(p9, p10);
jrha 0:75c7bfd01ea0 6 Serial pc(USBTX, USBRX);
jrha 0:75c7bfd01ea0 7
jrha 0:75c7bfd01ea0 8 int main()
jrha 0:75c7bfd01ea0 9 {
jrha 0:75c7bfd01ea0 10
jrha 0:75c7bfd01ea0 11 int readings[3] = {0, 0, 0};
jrha 0:75c7bfd01ea0 12
jrha 0:75c7bfd01ea0 13 pc.printf("Starting ADXL345 test...\n");
jrha 0:75c7bfd01ea0 14 pc.printf("Device ID is: 0x%02x\n", accelerometer.getDevId());
jrha 0:75c7bfd01ea0 15
jrha 0:75c7bfd01ea0 16 //Go into standby mode to configure the device.
jrha 0:75c7bfd01ea0 17 accelerometer.setPowerControl(0x00);
jrha 0:75c7bfd01ea0 18
jrha 0:75c7bfd01ea0 19 //Full resolution, +/-16g, 4mg/LSB.
jrha 0:75c7bfd01ea0 20 accelerometer.setDataFormatControl(0x0B);
jrha 0:75c7bfd01ea0 21
jrha 0:75c7bfd01ea0 22 //3.2kHz data rate.
jrha 0:75c7bfd01ea0 23 accelerometer.setDataRate(ADXL345_3200HZ);
jrha 0:75c7bfd01ea0 24
jrha 0:75c7bfd01ea0 25 //Measurement mode.
jrha 0:75c7bfd01ea0 26 accelerometer.setPowerControl(0x08);
jrha 0:75c7bfd01ea0 27
jrha 0:75c7bfd01ea0 28 while (1)
jrha 0:75c7bfd01ea0 29 {
jrha 0:75c7bfd01ea0 30
jrha 0:75c7bfd01ea0 31 wait(0.1);
jrha 0:75c7bfd01ea0 32
jrha 0:75c7bfd01ea0 33 accelerometer.getOutput(readings);
jrha 0:75c7bfd01ea0 34
jrha 0:75c7bfd01ea0 35 //13-bit, sign extended values.
jrha 0:75c7bfd01ea0 36 pc.printf("%i, %i, %i\n", (int16_t)readings[0], (int16_t)readings[1], (int16_t)readings[2]);
jrha 0:75c7bfd01ea0 37 }
jrha 0:75c7bfd01ea0 38
jrha 0:75c7bfd01ea0 39 }