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.
Fork of SerialPC by
main.cpp
00001 #include "mbed.h" 00002 Serial pc(USBTX, USBRX); 00003 Serial device(p28, p27); 00004 AnalogIn xis1(p15); 00005 AnalogIn xis2(p16); 00006 DigitalIn on1(p19); 00007 DigitalIn on2(p20); 00008 DigitalIn gun(p23); 00009 int X1,X2,frame1,frame2,frame3,frame; 00010 int main() 00011 { 00012 00013 device.baud(2400); 00014 00015 while (1) 00016 { X1=xis1*1000; 00017 X2=xis2*1000; 00018 if(X1>=380 & X1<=450) //interpreting the output of accelerometer 1,controls the LEFT-RIGHT motion of toy vehicle. 00019 frame1=0; 00020 if(X1>=470 & X1<=530) //interpreting the output of accelerometer 1,controls the LEFT-RIGHT motion of toy vehicle. 00021 frame1=1; 00022 if(X1>=550 & X1<=640) //interpreting the output of accelerometer 1,controls the LEFT-RIGHT motion of toy vehicle. 00023 frame1=2; 00024 00025 if(X2>=380 & X2<=450 ) //interpreting the output of accelerometer 1,controls the LEFT-RIGHT motion of toy vehicle. 00026 frame2=0; 00027 if(X2>=470 & X2<=530 ) //interpreting the output of accelerometer 1,controls the LEFT-RIGHT motion of toy vehicle. 00028 frame2=1; 00029 if(X2>=550 & X2<=640 ) //interpreting the output of accelerometer 1,controls the LEFT-RIGHT motion of toy vehicle. 00030 frame2=2; 00031 00032 if(on1==0 & on2==0) //two switchs used for controling on/off of gun and bot 00033 { 00034 frame3=0; 00035 } 00036 else if(on1==1 & on2==1) 00037 { 00038 frame3=3; 00039 } 00040 else if(on1==0 & on2==1) 00041 { 00042 frame3=1; 00043 } 00044 else if(on1==1 & on2==0) 00045 { 00046 frame3=2; 00047 } 00048 00049 //combining 3 values in 8bits for transmitting it serially 00050 frame=frame1+(4*frame2)+(16*frame3); 00051 device.putc(frame); 00052 00053 pc.printf("\n\n\r%d %d %d %d",frame,frame1,frame2,frame3); 00054 00055 00056 } 00057 }
Generated on Wed Jul 27 2022 02:31:08 by
1.7.2
