4 #if defined(TARGET_LPC812)
5 ADXL345 accelerometer(D10, D11, D12, D13);
8 ADXL345 accelerometer(p5, p6, p7, p8);
11 // Assume test configuration on a plane (small x and y, z ~ g)
16 void check_X_Y(int v) {
17 int16_t a = (int16_t)v;
18 if (abs(a) > MAX_X_Y) {
19 printf("X/Y acceleration is too big: %d\n", a);
20 notify_completion(false);
26 int readings[3] = {0, 0, 0};
28 printf("Starting ADXL345 test...\n");
29 printf("Device ID is: 0x%02x\n", accelerometer.getDevId());
31 //Go into standby mode to configure the device.
32 accelerometer.setPowerControl(0x00);
34 //Full resolution, +/-16g, 4mg/LSB.
35 accelerometer.setDataFormatControl(0x0B);
38 accelerometer.setDataRate(ADXL345_3200HZ);
41 accelerometer.setPowerControl(0x08);
43 for (int i=0; i<3; i++) {
46 //13-bit, sign extended values.
47 accelerometer.getOutput(readings);
50 check_X_Y(readings[0]);
51 check_X_Y(readings[1]);
54 int16_t z = (int16_t)readings[2];
55 if ((z < MIN_Z) || (z > MAX_Z)) {
56 printf("Z acceleration not within expected range\n", z);
57 notify_completion(false);
61 notify_completion(true);