Sumit Pandey
/
adxl335_mbed_serial
transmission of calibrated accelerometer data to the computer for Air Hockey.
Diff: main.cpp
- Revision:
- 0:6754c50b1d75
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sun Oct 27 18:30:26 2013 +0000 @@ -0,0 +1,26 @@ +#include "mbed.h" + +AnalogIn inputx(p20); // input pins 20,19,18 for x,y,z axis respectively. +AnalogIn inputy(p19); +AnalogIn inputz(p18); +Serial pc(USBTX,USBRX); //Serial class for transmission of serial data + +int main() { +pc.baud(9600); // fixing a constant baud rate of 9600 bps at which mbed will interact with computer +float cal_x=0,cal_y=0,cal_z=0; //caliberation variables +int x=0,y=0,z=0; // variables for x,y,z axes +int i=100; +while(i--) //small timed loop to caliberate the accelerometer with currentl position of the accelerometer +{ +cal_x=inputx*100; +cal_y=inputy*100; +cal_z=inputz*100 - 10; +} +while(1) + { + x=4*(cal_x - inputx*100); + y=4*(cal_y - inputy*100); + z=4*(inputz*100 - cal_z); + pc.printf("%d,%d,%d *",x+50,y+50,z+50); //passing the caliberated x,y,z values to the computer. + } + } \ No newline at end of file