Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: ADXL345_I2C ITG3200 mbed
Fork of ADXL345 by
Diff: main.cpp
- Revision:
- 1:67703f5eab67
- Parent:
- 0:75c7bfd01ea0
--- a/main.cpp Fri Mar 11 15:54:40 2011 +0000
+++ b/main.cpp Fri Jul 31 10:24:10 2015 +0000
@@ -1,39 +1,52 @@
#include "mbed.h"
#include "ADXL345_I2C.h"
+
-//ADXL345 accelerometer(p5, p6, p7, p8);
-ADXL345_I2C accelerometer(p9, p10);
+ADXL345_I2C acc(p9, p10);
Serial pc(USBTX, USBRX);
+
+void ADXL345_settings(){
+ //Go into standby mode to configure the device.
+ acc.setPowerControl(0x00);
+ wait(0.001);
+
+ //Full resolution, +/-16g, 4mg/LSB.
+ acc.setDataFormatControl(0x09);
+ wait(0.001);
+
+ //3.2kHz data rate.
+ acc.setDataRate(ADXL345_800HZ);
+ wait(0.001);
+
+ //Measurement mode.
+ acc.setPowerControl(0x08);
+ wait(0.001);
+}
int main()
{
+ wait(3);
+
+ pc.baud(9600);
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);
+
+ Timer acc_Timer;
+ const int acc_Time = 100;
+
+ acc_Timer.start();
- //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]);
+ pc.printf("Starting ADXL345 test...\n");
+ wait(0.001);
+ ADXL345_settings();
+ wait(0.1);
+
+ while(true){
+
+ if(acc_Timer.read_ms() >= acc_Time){
+ acc_Timer.reset();
+ acc.getOutput(readings);
+ pc.printf("%i %i %i\n", (int16_t)readings[0], (int16_t)readings[1], (int16_t)readings[2]);
}
-
+ }
}
