Engine control program with 3 engines Needs to make a case for each simultaneous engine setting, because of the WAIT after each number of bits have been sent.

Dependencies:   mbed-rtos mbed PinDetect

Fork of FinalMotorControl by Robot Bachelor

Revision:
5:fdc7a779d525
Parent:
4:4d655fdae399
Child:
6:ac5d277bd497
--- a/main.cpp	Wed Apr 13 10:10:23 2016 +0000
+++ b/main.cpp	Mon Apr 18 12:18:06 2016 +0000
@@ -4,15 +4,23 @@
 Serial pc(USBTX, USBRX); // tx, rx
 
 //Analog Pins
-DigitalOut IN1(D3);
-DigitalOut IN2(D4);
-DigitalOut IN3(D5);
-DigitalOut IN4(D6);
+//First engine
+DigitalOut IN1(A0);
+DigitalOut IN2(A1);
+DigitalOut IN3(A2);
+DigitalOut IN4(A3);
+//Second engine
+DigitalOut IN5(D2);
+DigitalOut IN6(D3);
+DigitalOut IN7(D4);
+DigitalOut IN8(D5);
+
 
 static int fart = 1000;
 static char m_cmd = 'x';
 
 
+
 void step4Right()
 {
     IN1=0;
@@ -75,6 +83,7 @@
          }
         
         Thread::wait(10);
+        //pc.printf("%d", steps);
     }
 }
 
@@ -85,6 +94,7 @@
         static char global_direction;
         printf("Started");
         
+        
         while (true) 
         {
             //Thread::wait(5);
@@ -93,8 +103,11 @@
             if (m_cmd == '0')
             {
                 fart = 1000;
-                global_direction = '0';
+                //global_direction = '0';
                 step4Left();
+                //steps = steps + step;
+                
+                
                 //printf("LEFT \n");
                 //printf("%c \n" + global_direction); 
             } 
@@ -102,37 +115,64 @@
             else if (m_cmd == '1')
             {
                 fart = 1000;
-                global_direction = '1';
+                //global_direction = '1';
                 step4Right();
+               // steps = steps + step;
+                //printf("%i", &steps);
                 //printf("RIGHT \n"); 
                 
             } 
                 else
             {
-                global_direction = 'x';
+                //global_direction = 'x';
             }
             if (m_cmd == 'a')
             {
                 fart =  2000;
-                global_direction = '1';
+                //global_direction = '1';
                 step4Right();
+                //steps = steps + step;
+               // printf("%i", &steps);
                 
             }
 
             else if (m_cmd == 'c')
             {
                 fart = 2000;
-                global_direction = '0';
-                step4Left();
-            }
-            if (global_direction =='0')
-            {
+                //global_direction = '0';
                 step4Left();
+                
+                //steps = steps + step;
+               // printf("%i", &steps);
             }
-            else if (global_direction == '1')
+            else if (m_cmd == 'k')
             {
-                step4Right();
+                int steps = 485;
+                
+                
+                //Steps = 485 gives a 120' rotation to the left. 
+                while (steps >= 0)
+                {
+                    step4Left();
+                    steps--;
+                }
+                m_cmd = 'x';
             }
+            else if (m_cmd == 'l')
+            {
+                int steps = 485;
+                //Steps = 485 gives a 120' rotation to the right. 
+                while (steps >= 0)
+                {
+                    step4Right();
+                    steps--;
+                }
+                m_cmd = 'x';
+                
+            }
+            
+
+
 
         }