TUK Workshop

Dependencies:   mbed lib_workshop_2019

Files at this revision

API Documentation at this revision

Comitter:
tuk4
Date:
Thu Oct 24 13:23:03 2019 +0000
Parent:
8:c2d06715025f
Commit message:
changes TUK 24-10-2019

Changed in this revision

includes/pin_connexions.h Show annotated file Show diff for this revision Revisions of this file
includes/test_motor.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
src/test_motor/test_motor.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/includes/pin_connexions.h	Thu Oct 24 06:06:55 2019 +0000
+++ b/includes/pin_connexions.h	Thu Oct 24 13:23:03 2019 +0000
@@ -24,6 +24,7 @@
 /****************************************/
 // Place your Serial declaration here
 
+Serial pc (PA_2, PA_3, 115200);
 
 
 
@@ -31,9 +32,9 @@
 /**         CNY declarations           **/
 /*          To be completed             */ 
 // Declare your CNY70 here
-
-
-
+AnalogIn cny_1 (PA_7); 
+AnalogIn cny_2 (PC_2); 
+AnalogIn cny_3 (PC_3); 
 
 /**     End of CNY declaration         **/
 /****************************************/
@@ -43,13 +44,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);
+ 
 
 /**  End of Motor by PWM declarations  **/
 /****************************************/
@@ -60,4 +62,7 @@
 /* Compass sensor */
 CMPS03      compass           (PC_4);
 
+/*    Interrupt   */
+InterruptIn blue_button_interupt (PC_13);
+
 #endif /* PINCONNEXIONS_H */
--- a/includes/test_motor.h	Thu Oct 24 06:06:55 2019 +0000
+++ b/includes/test_motor.h	Thu Oct 24 13:23:03 2019 +0000
@@ -9,9 +9,9 @@
  
 #ifndef TEST_MOTOR_H
 #define TEST_MOTOR_H
-
+ 
 #include "mbed.h"
-
+ 
 enum e_direction {
     FORWARD,
     BACKWARD
@@ -23,7 +23,9 @@
 void ft_run_motor(e_direction direction, double duty_cycle, PwmOut pwm_mot, DigitalOut  dirA, DigitalOut  dirB);
 
 void ft_test_motor(PwmOut pin_pwm_mot, DigitalOut pin_dirA, DigitalOut pin_dirB, Serial &pc); 
-
-
-
-#endif
\ No newline at end of file
+ 
+ 
+void change_direction();
+ 
+#endif
+            
\ No newline at end of file
--- a/main.cpp	Thu Oct 24 06:06:55 2019 +0000
+++ b/main.cpp	Thu Oct 24 13:23:03 2019 +0000
@@ -8,15 +8,22 @@
 
 #include "pin_connexions.h"
 
+
 int main() {
     e_test user_choice ;
     ft_print_test_menu(pc);
     user_choice = ft_get_user_choice(pc);
+    blue_button_interupt.fall(&change_direction);    
+    
+    
     
     
     /* Main loop */
     while(1)
     {
+        
+        wait_ms(250);
+        
         /* Which component to test ? */
         switch (user_choice) 
         {
@@ -42,11 +49,11 @@
             do
             {
                 pc.printf("\r CNY_1");
-                //ft_print_cny_analog_voltage(CNY1, pc);
+                ft_print_cny_analog_voltage(cny_1, pc);
                 pc.printf("\t CNY_2");
-                //ft_print_cny_analog_voltage(CNY2, pc);
+                ft_print_cny_analog_voltage(cny_2, pc);
                 pc.printf("\t CNY_3");
-                //ft_print_cny_analog_voltage(CNY3, pc);
+                ft_print_cny_analog_voltage(cny_3, pc);
             } while (!pc.readable());
             pc.printf("\n");
             user_choice = ft_get_user_choice(pc);
@@ -62,12 +69,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	Thu Oct 24 06:06:55 2019 +0000
+++ b/src/test_cny/ft_print_value_cny.cpp	Thu Oct 24 13:23:03 2019 +0000
@@ -15,7 +15,10 @@
 {
     const double max_voltage = 3.3;
     /* TO BE IMPLEMENTED */
-
+    double value = analog_input.read();
+    double voltage = value * 12;
+    pc.printf("Voltage value : %lf", voltage);
+    
     return;
 }
 
--- a/src/test_motor/ft_run_motor.cpp	Thu Oct 24 06:06:55 2019 +0000
+++ b/src/test_motor/ft_run_motor.cpp	Thu Oct 24 13:23:03 2019 +0000
@@ -16,15 +16,17 @@
     
     if (direction == FORWARD)
     {
-       
+       dirA = 1;
+       dirB = 0;
        
     }
-    else // direction == BACKWARD
+    else if (direction == BACKWARD)
     {
-      
-      
+      dirA = 0;
+      dirB = 1; 
     }
+
     
     /* TO DO : apply duty cycle to pwm_mot */
-
+    pwm_mot = duty_cycle;
 }
--- a/src/test_motor/test_motor.cpp	Thu Oct 24 06:06:55 2019 +0000
+++ b/src/test_motor/test_motor.cpp	Thu Oct 24 13:23:03 2019 +0000
@@ -2,13 +2,13 @@
 #include "test_motor.h"
 #include "console_output.h"
 
-
+e_direction direction = FORWARD;
 
 
 void ft_test_motor(PwmOut pin_pwm_mot, DigitalOut pin_dirA, DigitalOut pin_dirB,
                     Serial &pc)
 {
-    e_direction direction = FORWARD;
+
     
     int user_int=1;
     double duty_cycle =0.1;
@@ -24,4 +24,15 @@
     } while (user_int > 0);
     
     return;
-}
\ No newline at end of file
+}
+
+void change_direction(){
+        if (direction == FORWARD)
+        {
+            direction = BACKWARD;
+        }
+        else 
+        {
+           direction = FORWARD;
+        }
+    }
\ No newline at end of file