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: mbed
Revision 0:8c7b1674d5eb, committed 2014-12-18
- Comitter:
- WAT34
- Date:
- Thu Dec 18 15:43:21 2014 +0000
- Commit message:
- ADXL345 tilt;
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Dec 18 15:43:21 2014 +0000 @@ -0,0 +1,37 @@ +#include "mbed.h" +#include "math.h" +#define pi 3.1415 +I2C sensor(p9,p10); //using ADXL345 +Serial pc(USBTX,USBRX); +int main() { + int addr = 0x1D; //set device's address + int i; + double a[2],t; + short data[3]; + char rd_val[6]; + char start[2] = {0x2D,0x08}; + char get_val[6] ={0x32}; + sensor.write(addr<<1,start,2); + while(1) { + sensor.write(addr<<1,get_val,1); + sensor.read((addr<<1)+1,rd_val,6); + i = 0; + while(i<3){ + data[i] =(rd_val[2*i+1]<<8)+rd_val[2*i]; + i++; + } + i = 0; + while(i<3){ + a[i] = data[i]*4.0/1024.0; + pc.printf("val%d--->%lfG\n\r",i,a[i]); + + i++; + } + t = atan(a[0]/a[1]); + t = 180/pi*t; + pc.printf("t=%lf\n\r",t); + wait(1); + + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Thu Dec 18 15:43:21 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/4fc01daae5a5 \ No newline at end of file