Ramon Waninge / Mbed 2 deprecated Milestone1

Dependencies:   FastPWM mbed QEI biquadFilter HIDScope MODSERIAL

Revision:
22:71524e4fd1f2
Parent:
21:363271dcfe1f
Child:
23:0c02cf961344
--- a/main.cpp	Mon Oct 22 14:50:31 2018 +0000
+++ b/main.cpp	Mon Oct 29 11:35:49 2018 +0000
@@ -41,7 +41,7 @@
 
 // Global variables
 const float    pi = 3.14159265358979;
-float u3 = 0.0;         // Normalised variable for the movement of motor 3
+double u3 = 0.0;         // Normalised variable for the movement of motor 3
 
 // Functions
 void Encoderinput()
@@ -58,7 +58,7 @@
     angle2 = ((float)counts2*2.0*pi)/4200.0;
     angle3 = ((float)counts3*2.0*pi)/4200.0;
          
-    pc.printf("Counts3: %i  Angle3: %f      Counts2: %i  Angle2: %f\r\n",counts3,angle3,counts2,angle2);
+    pc.printf("Counts1,2,3: %i %i %i  Angle1,2,3: %f %f %f  \r\n",counts1,counts2,counts3,angle1,angle2,angle3);
 }
 
 void draaibuttons()         
@@ -88,23 +88,26 @@
     shield for the moving direction and speed of motor 3.
 */
 {      
-    float u1 = 2.0*(pot1 - 0.5);    // Normalised variable for the movement of motor 1
+    double u1 = 2.0*(pot1 - 0.5);    // Normalised variable for the movement of motor 1
     if (u1>0)
     {   pin4 = true;
     }
     else if(u1<0)
     {   pin4 = false;    
     }
+    pin5.period(0.2);   // Set PWM period to 0.2 seconds
     pin5 = fabs(u1);
+    //pin5.write(fabs(u1));    // Set duty cycle (and thus the angle of the motor) to potmeter percentage
     
-    float u2 = 2.0*(pot2 - 0.5);    // Normalised variable for the movement of motor 2
+    double u2 = 2.0*(pot2 - 0.5);    // Normalised variable for the movement of motor 2
     if (u2<0)
     {   pin7 = true;
     }
     else if(u2>0)
     {   pin7 = false;    
     }
-    pin6 = fabs(u2);  
+    pin6.period(0.2);   // Set PWM period to 0.2 seconds
+    //pin6.write(fabs(u2));    // Set output duty cycle (and thus the angle of the motor) to potmeter percentage
     
     if (u3>0)
     {   pin2 = true;
@@ -115,28 +118,20 @@
     else
     {   pin3 = 0;
     }
-    pin3 = fabs(u3);   
+    pin3.period(0.2);   // Set PWM period to 0.2 seconds
+    //pin3.write(fabs(u3));    // Set duty cycle (and thus the angle of the motor) to potmeter percentage   
 }
 
 // Main program
 int main()
 {   
     pc.baud(115200);
-        
-    pin5.period(1.0/10000);
+    
     button1.rise(&draaibuttons);       
     button2.rise(&draaibuttons);
     
-    pin3.period_us(50);
     motor.attach(draai, 0.001);
-   
-    pin5.period_us(50);
-    motor.attach(draai, 0.001);
-    
-    pin6.period_us(50);
-    motor.attach(draai, 0.001);
-
-            
+        
     while   (true)
     {   Encoderinput();
     }