NITH ece
/
group3_transmiiter
transmitter code
Fork of SerialPC by
main.cpp
- Committer:
- kit2
- Date:
- 2013-10-30
- Revision:
- 1:71d38917bdce
- Parent:
- 0:06ea14e458e3
File content as of revision 1:71d38917bdce:
#include "mbed.h" Serial pc(USBTX, USBRX); Serial device(p28, p27); AnalogIn xis1(p15); AnalogIn xis2(p16); DigitalIn on1(p19); DigitalIn on2(p20); DigitalIn gun(p23); int X1,X2,frame1,frame2,frame3,frame; int main() { device.baud(2400); while (1) { X1=xis1*1000; X2=xis2*1000; if(X1>=380 & X1<=450) //interpreting the output of accelerometer 1,controls the LEFT-RIGHT motion of toy vehicle. frame1=0; if(X1>=470 & X1<=530) //interpreting the output of accelerometer 1,controls the LEFT-RIGHT motion of toy vehicle. frame1=1; if(X1>=550 & X1<=640) //interpreting the output of accelerometer 1,controls the LEFT-RIGHT motion of toy vehicle. frame1=2; if(X2>=380 & X2<=450 ) //interpreting the output of accelerometer 1,controls the LEFT-RIGHT motion of toy vehicle. frame2=0; if(X2>=470 & X2<=530 ) //interpreting the output of accelerometer 1,controls the LEFT-RIGHT motion of toy vehicle. frame2=1; if(X2>=550 & X2<=640 ) //interpreting the output of accelerometer 1,controls the LEFT-RIGHT motion of toy vehicle. frame2=2; if(on1==0 & on2==0) //two switchs used for controling on/off of gun and bot { frame3=0; } else if(on1==1 & on2==1) { frame3=3; } else if(on1==0 & on2==1) { frame3=1; } else if(on1==1 & on2==0) { frame3=2; } //combining 3 values in 8bits for transmitting it serially frame=frame1+(4*frame2)+(16*frame3); device.putc(frame); pc.printf("\n\n\r%d %d %d %d",frame,frame1,frame2,frame3); } }