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.
main.cpp
00001 //Base Unit containing the accelerometer and the Xbee Module 00002 #include "mbed.h" 00003 #include "ADXL345.h" 00004 00005 ADXL345 accelerometer(p5, p6, p7, p8); 00006 Serial pc(USBTX, USBRX); 00007 00008 Serial xbee1(p9, p10); 00009 DigitalOut rst1(p11); 00010 00011 00012 DigitalOut myled(LED3);//Create variable for Led 3 on the mbed 00013 00014 int main() { 00015 00016 // reset the xbees (at least 200ns) 00017 rst1 = 0; 00018 // rst2 = 0; 00019 wait_ms(1); 00020 rst1 = 1; 00021 // rst2 = 1; 00022 wait_ms(1); 00023 00024 int readings[3] = {0, 0, 0}; 00025 00026 pc.printf("Starting ADXL345 test...\n"); 00027 pc.printf("Device ID is: 0x%02x\n", accelerometer.getDevId()); 00028 00029 //Go into standby mode to configure the device. 00030 accelerometer.setPowerControl(0x00); 00031 00032 //Full resolution, +/-16g, 4mg/LSB. 00033 accelerometer.setDataFormatControl(0x0B); 00034 00035 //3.2kHz data rate. 00036 accelerometer.setDataRate(ADXL345_3200HZ); 00037 00038 //Measurement mode. 00039 accelerometer.setPowerControl(0x08); 00040 00041 while(1) { 00042 00043 wait(0.5); 00044 00045 accelerometer.getOutput(readings); 00046 00047 //13-bit, sign extended values. 00048 pc.printf("%f, %f, %f\n\r", (float)readings[0]/65535, (float)readings[1]/65535, (float)readings[2]/65535); 00049 00050 if ((float)readings[1]/65535 > 0.5) 00051 xbee1.putc('C'); //Forward 00052 if ((float)readings[1]/65535 < 0.5) 00053 xbee1.putc('D'); //Reverse 00054 myled = 1; 00055 wait_ms(100); 00056 myled=0; 00057 wait_ms(100); 00058 00059 } 00060 }
Generated on Fri Jul 15 2022 04:34:04 by
1.7.2