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
main.cpp
- Committer:
- WAT34
- Date:
- 2014-12-18
- Revision:
- 0:8c7b1674d5eb
File content as of revision 0:8c7b1674d5eb:
#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); } }