Overzetten

Dependencies:   HIDScope MODSERIAL mbed

Revision:
4:a1691164d879
Parent:
3:4f5a67f4170b
Child:
5:0ae4951e9b81
--- a/main.cpp	Fri Oct 05 11:14:08 2018 +0000
+++ b/main.cpp	Fri Oct 05 11:42:05 2018 +0000
@@ -17,31 +17,13 @@
 AnalogIn    emg1( A1 );
 
 Ticker      sample_timer;
-HIDScope    scope( 2 );
+//HIDScope    scope( 2 );
 DigitalOut  led(LED1);
 
 
-void sample()
+int Turn_Motor1()
 {
-    
-    scope.set(0, emg0.read() );
-    scope.set(1, emg1.read() );
-  
-    scope.send();
-    led = !led;
-}
-
-
-int main()
-{
-    
-    pc.baud(115200);     
-    sample_timer.attach(&sample, 0.002);
-    PwmPin1.period_us(120); //60 microseconds pwm period, 16.7 kHz 
-    
-    for(;;)
-    {
-        if(Knop1==false) // Motor 1 rotates CW
+    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
@@ -50,15 +32,7 @@
             PwmPin2 = fabs(0.0); 
         }
         
-        else if (Knop2==false)// We see that Motor2 keeps rotating if we leave out the "else" statement, somehow the signal leaks
-        {
-            float u = 0.8f;
-            DirectionPin2 = u < 0.0f;
-            PwmPin1 = fabs(0.0);
-            PwmPin2 = fabs(u);
-        }
-    
-        else if (Knop3==false)
+        else if (Knop3==false)// We see that Motor2 keeps rotating if we leave out the "else" statement, somehow the signal leaks
         {
             float u = 0.8f;
             DirectionPin1 = u < 0.0f;
@@ -66,6 +40,24 @@
             PwmPin2 = fabs(0.0);  
         }
         
+        else
+        {  
+            float u = 0.0f;
+            PwmPin1 = fabs(u);
+        }
+    return 0;
+}
+
+int Turn_Motor2()
+{
+    if (Knop2==false)
+        {
+            float u = 0.8f;
+            DirectionPin2 = u < 0.0f;
+            PwmPin1 = fabs(0.0);
+            PwmPin2 = fabs(u);  
+        }
+        
         else if (Knop4==false)
         {
             float u = 0.8f;
@@ -78,7 +70,32 @@
         else
         {  
             float u = 0.0f;
-            PwmPin1 = PwmPin2 = fabs(u);
+            PwmPin2 = fabs(u);
         }
+    return 0;
+}
+/*
+void sample()
+{
+    
+    scope.set(0, emg0.read() );
+    scope.set(1, emg1.read() );
+  
+    scope.send();
+    led = !led;
+}
+*/
+
+int main()
+{
+    
+    pc.baud(115200);     
+   // sample_timer.attach(&sample, 0.002);
+    PwmPin1.period_us(120); //60 microseconds pwm period, 16.7 kHz 
+    
+    for(;;)
+    {
+        Turn_Motor1();
+        Turn_Motor2();        
     }
 }
\ No newline at end of file