![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Code for Base Module
Revision 0:7cf9c0ff4ce8, committed 2011-02-27
- Comitter:
- buntyshubho
- Date:
- Sun Feb 27 06:11:25 2011 +0000
- Commit message:
Changed in this revision
diff -r 000000000000 -r 7cf9c0ff4ce8 ADXL345.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ADXL345.lib Sun Feb 27 06:11:25 2011 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/aberk/code/ADXL345/#bd8f0f20f433
diff -r 000000000000 -r 7cf9c0ff4ce8 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sun Feb 27 06:11:25 2011 +0000 @@ -0,0 +1,60 @@ +//Base Unit containing the accelerometer and the Xbee Module +#include "mbed.h" + #include "ADXL345.h" + + ADXL345 accelerometer(p5, p6, p7, p8); + Serial pc(USBTX, USBRX); + +Serial xbee1(p9, p10); +DigitalOut rst1(p11); + + +DigitalOut myled(LED3);//Create variable for Led 3 on the mbed + +int main() { + + // reset the xbees (at least 200ns) + rst1 = 0; + // rst2 = 0; + wait_ms(1); + rst1 = 1; + // rst2 = 1; + wait_ms(1); + + 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); + + //3.2kHz data rate. + accelerometer.setDataRate(ADXL345_3200HZ); + + //Measurement mode. + accelerometer.setPowerControl(0x08); + + while(1) { + + wait(0.5); + + accelerometer.getOutput(readings); + + //13-bit, sign extended values. + pc.printf("%f, %f, %f\n\r", (float)readings[0]/65535, (float)readings[1]/65535, (float)readings[2]/65535); + + if ((float)readings[1]/65535 > 0.5) + xbee1.putc('C'); //Forward + if ((float)readings[1]/65535 < 0.5) + xbee1.putc('D'); //Reverse + myled = 1; + wait_ms(100); + myled=0; + wait_ms(100); + + } +}
diff -r 000000000000 -r 7cf9c0ff4ce8 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Sun Feb 27 06:11:25 2011 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/63bcd7ba4912