transmitter code

Dependencies:   mbed

Fork of SerialPC by phil dani

Files at this revision

API Documentation at this revision

Comitter:
kit2
Date:
Wed Oct 30 13:37:20 2013 +0000
Parent:
0:06ea14e458e3
Commit message:
group 3 final transmitter code

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Sun Sep 01 10:33:17 2013 +0000
+++ b/main.cpp	Wed Oct 30 13:37:20 2013 +0000
@@ -1,22 +1,57 @@
-/*Program 5: Reads input voltage through the ADC, and transfers to PC terminal */
 #include "mbed.h"
-
-Serial pc(USBTX, USBRX); //enable serial port which links to USB
-AnalogIn Ain(p20);
-Timer t;
-float ADCdata;
-
-int main() {
-    pc.printf("ADC Data Values…\n\r"); //send an opening text message 
-    while(1){
-        t.start();
-         for (int i=0;i<=9;i++) {
-            ADCdata=ADCdata+Ain*3.3; //sum 10 samples
-        }
-        ADCdata=ADCdata/10; //divide by 10
-        wait(0.5);
-        pc.printf("%1.3f \n\r",ADCdata); //send the data to the terminal
-        t.stop();
-        printf("The time taken was %f seconds\n", t.read());
-    }
+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);
+      
+      
+     }
 }