Tuk tutoriail

Dependencies:   mbed lib_workshop_2019

Files at this revision

API Documentation at this revision

Comitter:
dgwambaa
Date:
Mon Oct 28 09:19:57 2019 +0000
Parent:
9:19255172362f
Commit message:
save test

Changed in this revision

includes/pin_connexions.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
src/test_cny/ft_print_value_cny.cpp Show annotated file Show diff for this revision Revisions of this file
src/test_motor/ft_run_motor.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/includes/pin_connexions.h	Mon Oct 28 05:29:08 2019 +0000
+++ b/includes/pin_connexions.h	Mon Oct 28 09:19:57 2019 +0000
@@ -22,14 +22,16 @@
 /****************************************/
 /* TO DO 1 : Declare the Serial connexion */
 /****************************************/
-// Place your Serial declaration here
+  Serial pc (PA_2, PA_3, 115200); // Place your Serial declaration here
 
 
 /****************************************/
 /**         CNY declarations           **/
 /*          To be completed             */ 
 // Declare your CNY70 here
-
+AnalogIn cny_1 (PA_7);
+AnalogIn cny_2 (PC_2);
+AnalogIn cny_3 (PC_3);
 
 
 
@@ -40,10 +42,14 @@
 /****************************************/
 /**     Motor by PWM declarations       **/
 /*          To be completed             */ 
-
+DigitalOut DIR_1L(PC_9);
+DigitalOut  DIR_2L(PC_8);
+DigitalOut  DIR_1R(PC_6);
+DigitalOut  DIR_2R(PC_5);
+PwmOut  Pwm_ML(PA_9);
+PwmOut  Pwm_MR(PA_8);
 
-
-
+InteruptIn
 
 
 
--- a/main.cpp	Mon Oct 28 05:29:08 2019 +0000
+++ b/main.cpp	Mon Oct 28 09:19:57 2019 +0000
@@ -42,11 +42,11 @@
             do
             {
                 pc.printf("\r CNY_1");
-                //ft_print_cny_analog_voltage(cny_1, pc);
+                ft_print_cny_analog_voltage(cny_1, pc);
                 pc.printf("\t CNY_2");
-                //ft_print_cny_analog_voltage(cny_2, pc);
+                ft_print_cny_analog_voltage(cny_2, pc);
                 pc.printf("\t CNY_3");
-                //ft_print_cny_analog_voltage(cny_3, pc);
+                ft_print_cny_analog_voltage(cny_3, pc);
             } while (!pc.readable());
             pc.printf("\n");
             user_choice = ft_get_user_choice(pc);
@@ -62,12 +62,12 @@
             break;
         
         case LEFT_MOTOR : 
-            ft_print_to_be_imp(pc); //TODO : Replace this line
+            ft_test_motor(Pwm_ML, DIR_1L, DIR_2L, pc);
             user_choice = ft_get_user_choice(pc);
             break;
             
         case RIGHT_MOTOR: 
-            ft_print_to_be_imp(pc); //TODO : Replace this line
+            ft_test_motor(Pwm_MR, DIR_1R, DIR_2R, pc);
             user_choice = ft_get_user_choice(pc);
             break;
             
--- a/src/test_cny/ft_print_value_cny.cpp	Mon Oct 28 05:29:08 2019 +0000
+++ b/src/test_cny/ft_print_value_cny.cpp	Mon Oct 28 09:19:57 2019 +0000
@@ -15,7 +15,12 @@
 {
     const double max_voltage = 3.3;
     /* TO BE IMPLEMENTED */
-
+    double value;
+    double voltage;
+    value=analog_input.read();
+    voltage=value * max_voltage;
+    
+    pc.printf("Voltage value : %lf ", voltage);
     return;
 }
 
--- a/src/test_motor/ft_run_motor.cpp	Mon Oct 28 05:29:08 2019 +0000
+++ b/src/test_motor/ft_run_motor.cpp	Mon Oct 28 09:19:57 2019 +0000
@@ -11,36 +11,38 @@
 /*          - dirA and dirB (DigitalOut): Pins to set the direction   */
 /**********************************************************************/
 void ft_run_motor(  e_direction direction, double duty_cycle,
-                    PwmOut pwm_mot, DigitalOut  dirA, DigitalOut  dirB)
+                    PwmOut pwm_mot, DigitalOut  dir1, DigitalOut  dir2)
 {
     
     /* TO DO : define direction */
-    
     if (direction == FORWARD)
     {
+       dir1=1;
+       dir2=0;
        
        
     }
     else // direction == BACKWARD
     {
-      
+       dir1=0;
+       dir2=1;
       
     }
     
     /* TO DO : apply duty cycle to pwm_mot */
-
+    pwm_mot=duty_cycle;
 }
 
 
-double ft_get_duty_cycle_choice(Serial pc) {
-    double duty_cycle = 0;
+double ft_get_duty_cycle_choice(Serial &pc, double duty_cycle_p) {
+    double duty_cycle = duty_cycle_p;
     
     if (pc.readable() )
         {
             int user_int = ft_get_user_int(pc);
             if (user_int < 10 && user_int >= 0) duty_cycle = user_int/10.0; 
         }
-        return duty_cycle;
+    return duty_cycle;
 }
 
 void ft_test_motor(PwmOut pin_pwm_mot, DigitalOut pin_dirA, DigitalOut pin_dirB,
@@ -51,7 +53,8 @@
     double duty_cycle =0.1;
     
     do{
-        duty_cycle = ft_get_duty_cycle_choice(pc);
+        pc.printf("\r Duty cycle is %lf", duty_cycle);
+        duty_cycle = ft_get_duty_cycle_choice(pc, duty_cycle);
         ft_run_motor(direction, duty_cycle, pin_pwm_mot, pin_dirA, pin_dirB);
     } while (duty_cycle > 0.0);