No.9 Robotics / Mbed 2 deprecated Robotics_DCMotor

Dependencies:   mbed

Fork of Robotics_Lab_DCMotor by LDSC_Robotics

Revision:
4:04702de80697
Parent:
3:178ee1fe1c60
Child:
5:ff3b5f31a9ce
diff -r 178ee1fe1c60 -r 04702de80697 main.cpp
--- a/main.cpp	Wed Apr 13 09:07:29 2016 +0000
+++ b/main.cpp	Thu Apr 14 08:47:12 2016 +0000
@@ -8,7 +8,6 @@
 #define Ki 0.001f
 
 Serial bluetooth(D10,D2); //宣告藍牙腳位
-Serial pc(D1, D0);
 
 PwmOut pwm1(D7);
 PwmOut pwm1n(D11);
@@ -25,7 +24,6 @@
 InterruptIn HallA_2(D13);
 InterruptIn HallB_2(D12);
 
-Serial pc(D1, D0);
 
 Ticker timer1;
 void timer1_interrupt(void);
@@ -34,6 +32,9 @@
 void init_TIMER(void);
 void init_PWM(void);
 void init_CN(void);
+void init_BLUETOOTH(void);
+
+char speedCmd;
 
 int8_t stateA_1=0, stateB_1=0, stateA_2=0, stateB_2=0;
 int8_t state_1 = 0, state_1_old = 0, state_2 = 0, state_2_old = 0;
@@ -48,9 +49,6 @@
 
 int main() {
     
-    bluetooth.baud(115200);
-    pc.baud(57600);
-    
     init_TIMER();
     init_PWM();
     init_CN();
@@ -60,31 +58,26 @@
     
     while(1) 
     {
-        if(pc.readable())
-        {
-            bluetooth.putc(pc.getc());   
-        }
         if(bluetooth.readable())
         {
-            angle = bluetooth.getc();
-            pc.putc(speedCommand);
+           speedCmd = bluetooth.getc();
             
-            if (speedCommand == 'a')
+            if (speedCmd == 'a')
             { 
                 v1_ref = v1_ref + 10;
                 v2_ref = v2_ref + 10;
             }
-            else if (speedCommand == 's')
+            else if (speedCmd == 's')
             {
                 v1_ref = v1_ref - 10;
                 v2_ref = v2_ref - 10;
             }
-            else if (speedCommand == 'q')
+            else if (speedCmd == 'q')
             {
                 v1_ref = v1_ref + 20;
                 v2_ref = v2_ref + 20;
             }
-            else if (speedCommand == 'w')
+            else if (speedCmd == 'w')
             {
                 v1_ref = v1_ref - 20;
                 v2_ref = v2_ref - 20;
@@ -93,7 +86,7 @@
             if (v1_ref < -100)
                 v1_ref = -100;
             else if (v1_ref > 100)
-                v1_ref = 100
+                v1_ref = 100;
                 
             if (v2_ref < -100)
                 v2_ref = -100;
@@ -152,14 +145,14 @@
         if (stateB_1 == 0)
             state_1 = 1;
         else
-            stete_1 = 2;
+            state_1 = 2;
     }
     else
     {
         if (stateB_1 == 1)
             state_1 = 3;
         else
-            stete_1 = 4;
+            state_1 = 4;
     }
     
     //Forward: v1Count +1
@@ -181,14 +174,14 @@
         if (stateB_2 == 0)
             state_2 = 1;
         else
-            stete_2 = 2;
+            state_2 = 2;
     }
     else
     {
         if (stateB_2 == 1)
             state_2 = 3;
         else
-            stete_2 = 4;
+            state_2 = 4;
     }
     
     //Forward: v2Count +1
@@ -231,4 +224,9 @@
     stateB_1 = HallB_1.read();
     stateA_2 = HallA_2.read();
     stateB_2 = HallB_2.read();
+}
+
+void init_BLUETOOTH(void)
+{
+    bluetooth.baud(115200);
 }
\ No newline at end of file