Overzetten

Dependencies:   HIDScope MODSERIAL mbed

Revision:
5:0ae4951e9b81
Parent:
4:a1691164d879
Child:
6:bbef54156775
--- a/main.cpp	Fri Oct 05 11:42:05 2018 +0000
+++ b/main.cpp	Mon Oct 08 08:25:44 2018 +0000
@@ -12,24 +12,11 @@
 DigitalIn Knop3(PTA4);
 DigitalIn Knop4(PTC6);
 
-//Define objects
-AnalogIn    emg0( A0 );
-AnalogIn    emg1( A1 );
-
-Ticker      sample_timer;
-//HIDScope    scope( 2 );
-DigitalOut  led(LED1);
-
-
 int Turn_Motor1()
 {
-    if(Knop1==false) // Motor 1 rotates CW
+    if(!Knop1 && !Knop3 == true) // Motor 1 rotates CW
         {
-            float u = 0.8f; //determine useful value, this is not final
-            DirectionPin1 = u > 0.0f; //either true or false
-                                    // True = CW, for False = CW
-            PwmPin1 = fabs(u);
-            PwmPin2 = fabs(0.0); 
+            PwmPin1 = fabs(0.0); 
         }
         
         else if (Knop3==false)// We see that Motor2 keeps rotating if we leave out the "else" statement, somehow the signal leaks
@@ -40,6 +27,15 @@
             PwmPin2 = fabs(0.0);  
         }
         
+        else if (Knop1==false) // Motor 1 rotates CW
+        {
+            float u = 0.8f; //determine useful value, this is not final
+            DirectionPin1 = u > 0.0f; //either true or false
+                                    // True = CW, for False = CW
+            PwmPin1 = fabs(u);
+            PwmPin2 = fabs(0.0); 
+        }
+        
         else
         {  
             float u = 0.0f;
@@ -50,12 +46,9 @@
 
 int Turn_Motor2()
 {
-    if (Knop2==false)
+    if (!Knop2 && !Knop4 == true)
         {
-            float u = 0.8f;
-            DirectionPin2 = u < 0.0f;
-            PwmPin1 = fabs(0.0);
-            PwmPin2 = fabs(u);  
+            PwmPin2 = fabs(0.0);
         }
         
         else if (Knop4==false)
@@ -67,6 +60,14 @@
 
         }
         
+        else if (Knop2==false)
+        {
+            float u = 0.8f;
+            DirectionPin2 = u < 0.0f;
+            PwmPin1 = fabs(0.0);
+            PwmPin2 = fabs(u);  
+        }
+        
         else
         {  
             float u = 0.0f;
@@ -74,7 +75,15 @@
         }
     return 0;
 }
-/*
+
+//Define objects
+AnalogIn    emg0( A0 );
+AnalogIn    emg1( A1 );
+
+Ticker      sample_timer;
+HIDScope    scope( 2 );
+DigitalOut  led(LED1);
+
 void sample()
 {
     
@@ -84,13 +93,12 @@
     scope.send();
     led = !led;
 }
-*/
 
 int main()
 {
     
     pc.baud(115200);     
-   // sample_timer.attach(&sample, 0.002);
+    sample_timer.attach(&sample, 0.002);
     PwmPin1.period_us(120); //60 microseconds pwm period, 16.7 kHz 
     
     for(;;)