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.
Fork of ADXL345_I2C by
main.cpp
00001 #include "ADXL345_I2C.h" 00002 00003 DigitalOut myled(LED1); 00004 ADXL345_I2C accelerometer(p9, p10); 00005 Serial pc(USBTX, USBRX); 00006 00007 int main() { 00008 pc.baud(115200); 00009 // pc.baud(9600); 00010 myled = 1; 00011 00012 int readings[3] = {0, 0, 0}; 00013 00014 pc.printf("Starting ADXL345 test...\n"); 00015 wait(.001); 00016 pc.printf("Device ID is: 0x%02x\n", accelerometer.getDeviceID()); 00017 wait(.001); 00018 00019 // These are here to test whether any of the initialization fails. It will print the failure 00020 if (accelerometer.setPowerControl(0x00)){ 00021 pc.printf("didn't intitialize power control\n"); 00022 return 0; 00023 } 00024 //Full resolution, +/-16g, 4mg/LSB. 00025 wait(.001); 00026 00027 if(accelerometer.setDataFormatControl(0x0B)){ 00028 pc.printf("didn't set data format\n"); 00029 return 0; } 00030 wait(.001); 00031 00032 //3.2kHz data rate. 00033 if(accelerometer.setDataRate(ADXL345_3200HZ)){ 00034 pc.printf("didn't set data rate\n"); 00035 return 0; 00036 } 00037 wait(.001); 00038 00039 //Measurement mode. 00040 00041 if(accelerometer.setPowerControl(MeasurementMode)) { 00042 pc.printf("didn't set the power control to measurement\n"); 00043 return 0; 00044 } 00045 myled = 0; 00046 00047 while (1) { 00048 wait(0.1); 00049 00050 accelerometer.getOutput(readings); 00051 pc.printf("%+4.2f, %+4.2f, %+4.2f\n", 00052 (float((int16_t)readings[0]+18)/256), 00053 (float((int16_t)readings[1]-4 )/256), 00054 (float((int16_t)readings[2]+22)/256)); 00055 } 00056 }
Generated on Tue Jul 12 2022 22:58:51 by
1.7.2
