eLab Team / Mbed OS DcMotorTest
Revision:
1:77096ac47e7a
Parent:
0:708b17957be1
Child:
2:72952132894a
diff -r 708b17957be1 -r 77096ac47e7a main.cpp
--- a/main.cpp	Thu Jan 28 09:51:37 2021 +0000
+++ b/main.cpp	Thu Jan 28 15:51:12 2021 +0000
@@ -8,13 +8,23 @@
 DigitalIn my_button(USER_BUTTON); // Use the user button to switch from dc motor to servo motor and vice versa
 DigitalIn end_stop(D2); // relais fin de course
 
-PwmOut l1_dc_motor_en(D6);
-DigitalOut l1_dc_motor_cw(D7);
-DigitalOut l1_dc_motor_ccw(D8);
+PwmOut l1_dc_motor_en(D0);
+DigitalOut l1_dc_motor_cw(D1);
+DigitalOut l1_dc_motor_ccw(D2);
+
+PwmOut l1_servo_en(D5);
+DigitalOut l1_servo_cw(D3);
+DigitalOut l1_servo_ccw(D4);
+
 
-PwmOut l1_servo_en(D4);
-DigitalOut l1_servo_cw(D5);
-DigitalOut l1_servo_ccw(D3);
+PwmOut l2_dc_motor_en(D6);
+DigitalOut l2_dc_motor_cw(D7);
+DigitalOut l2_dc_motor_ccw(D8);
+
+PwmOut l2_servo_en(D11);
+DigitalOut l2_servo_cw(D9);
+DigitalOut l2_servo_ccw(D10);
+
 
 void run_l1_dc_motor_cw(void){
     l1_dc_motor_en.period_ms(20);    // shoul be 20 ms (490 Hz) and 10 ms for the servo (980 Hz)
@@ -28,9 +38,26 @@
     l1_dc_motor_cw=1;
     l1_dc_motor_ccw=0;
 }
+void run_l2_dc_motor_cw(void){
+    l2_dc_motor_en.period_ms(20);    // shoul be 20 ms (490 Hz) and 10 ms for the servo (980 Hz)
+    l2_dc_motor_en.pulsewidth_us(3000);
+    l2_dc_motor_cw=0;
+    l2_dc_motor_ccw=1;
+}
+void run_l2_dc_motor_ccw(void){
+    l2_dc_motor_en.period_ms(20);    // shoul be 20 ms (490 Hz) and 10 ms for the servo (980 Hz)
+    l2_dc_motor_en.pulsewidth_us(3000);
+    l2_dc_motor_cw=1;
+    l2_dc_motor_ccw=0;
+}
+
+
 void stop_dc_motor(void){
     l1_dc_motor_cw=0;
     l1_dc_motor_ccw=0; 
+    l2_dc_motor_cw=0;
+    l2_dc_motor_ccw=0;
+
 }
 
 void run_l1_servo_cw(void){
@@ -111,10 +138,25 @@
             stop_servo();
             printf("run_l1_servo_ccw\r\n");
         }     
+        if(cmd == '6')
+        {
+            cmd = 0;
+            run_l2_dc_motor_cw();    
+            printf("run_l2_dc_motor_cw\r\n");
+        }
+        if(cmd == '7')
+        {
+            cmd = 0;
+            run_l2_dc_motor_ccw();
+            printf("run_l2_dc_motor_ccw\r\n");
+        }
+
+
+
         if(cmd == 'h')
         {
             cmd=0;
-            printf("1=stop_dc_motor; 2=run_l1_dc_motor_cw; 3=run_l1_dc_motor_ccw; 4=run_l1_servo_cw; 5=run_l1_servo_ccw");
+            printf("1=stop_dc_motor; 2=run_l1_dc_motor_cw; 3=run_l1_dc_motor_ccw; 4=run_l1_servo_cw; 5=run_l1_servo_ccw, 6=run_l1_dc_motor_cw; 7=run_l1_dc_motor_ccw\n");
         }
     }