This library enables users to communicate with the ADXL345 accelerometer through the I2C bus on the mbed. The API names are similar and work nearly the same way as those made in the SPI libraries for the ADXL345.
Fork of ADXL345_I2C by
Diff: main.cpp
- Revision:
- 2:c2067856a052
- Parent:
- 0:d0adb548714f
--- a/main.cpp Thu May 12 01:19:36 2011 +0000 +++ b/main.cpp Mon Oct 02 08:28:52 2017 +0000 @@ -1,11 +1,13 @@ #include "ADXL345_I2C.h" - ADXL345_I2C accelerometer(p28, p27); + ADXL345_I2C accelerometer(D14, D15); Serial pc(USBTX, USBRX); + + DigitalIn button(USER_BUTTON); int main() { pc.baud(115200); - int readings[3] = {0, 0, 0}; + int16_t readings[3] = {0, 0, 0}; pc.printf("Starting ADXL345 test...\n"); wait(.001); @@ -35,15 +37,22 @@ if(accelerometer.setPowerControl(MeasurementMode)) { pc.printf("didn't set the power control to measurement\n"); return 0; } - + int nbPoints = 0; while (1) { - - wait(0.1); - - accelerometer.getOutput(readings); - - - pc.printf("%i, %i, %i\n", (int16_t)readings[0], (int16_t)readings[1], (int16_t)readings[2]); + + + if(button != 0){ + while(nbPoints < 3*10){ + wait(0.1); + accelerometer.getOutput(readings); + pc.printf("%d,%d,%d,\n",readings[0],readings[1],readings[2]); + //pc.printf("%f,%f,%f,", (float)((int16_t)readings[0]+1000)/2000.0, (float)((int16_t)readings[1]+1000)/2000.0, (float)((int16_t)readings[2]+1000)/2000.0); + + nbPoints += 3; + } + nbPoints = 0; + printf("\n"); + } } }