mohamedwajdi kharrat / Mbed 2 deprecated TP3_RBT_2GII_Ex2

Dependencies:   mbed

Revision:
1:fcdfb51a34c8
Parent:
0:ecb5de3a3147
Child:
2:c4ac4dc5673f
diff -r ecb5de3a3147 -r fcdfb51a34c8 main.cpp
--- a/main.cpp	Fri Apr 02 10:38:15 2021 +0000
+++ b/main.cpp	Sun Apr 04 19:59:00 2021 +0000
@@ -1,3 +1,14 @@
+//            Table des variables, des bits et des Registres d’E/S
+//_______________________________________________________________________________
+// Ports et variables d’E/S	   | Bits et Reg. d’E/S  |	Ecriture Modbus | Adresse
+// ------------------------------------------------------------------------------
+// Led2 : PB_8				   | bit 0 de BitsOut[0] | oui (fonction 5) | 0x1000
+// BP1 : PA_8				   | bit 0 de BitsIn[0]	 | non	            | 0x2000
+// BP2 : PB_12				   | bit 1 de BitsIn[0]	 | non	            | 0x2001
+// Rap_Cyc * 100 (pour Moteur) | RegOut[0]	         | oui (fonction 6) | 0x3000
+// Pot.read() * 100 (pour Led1)| RegOut[1]	         | non	            | 0x3001
+// Pot.read_u16 ()  (pour Pot) | RegIn[0]	         | non	            | 0x4000 
+//-------------------------------------------------------------------------------
 #include "mbed.h"
 #include "mb.h"
 
@@ -31,44 +42,41 @@
    eMBEnable();
 
    PwmOut moteur(PB_11);
-   PwmOut Led1(PB_10);
+   PwmOut Led1(..........);
    AnalogIn Pot(PA_0);
    DigitalIn BP1(PA_8,PullUp);
-   DigitalIn BP2(PB_12,PullUp);
+   DigitalIn BP2(..................);
    DigitalOut Led2(PB_8);
-   float Rap_Cyc=0;
-  
-    moteur.period_ms(.....);
-    Rap_Cyc=0;
-    RegOut[0]=0;
-    while(1)  { 
+   moteur.period_ms(.......);
+   RegOut[0]=20;  //RegOut[0] = rapport cyclique du moteur * 100 = 20% 
+   while(1)  { 
       //**** 1 ****//
       eMBPoll();
       //**** 2 ****//
-      if(BitsOut[0] & 0x01) Led2=......;
-      else  Led2=.......;
-      Rap_Cyc = ................/100.0;
+      if(BitsOut[0] & 0x01) Led2=1;  else  Led2=0;
+      moteur = RegOut[0]/100.0;
       //**** 3 ****//
-      if(!BP1 && Rap_Cyc <......) {
-         Rap_Cyc = Rap_Cyc + .........;
-         moteur = Rap_Cyc; 
+      if(!BP1 && RegOut[0] <100) {
+         RegOut[0] = RegOut[0] + 10;
+         moteur = RegOut[0]/.........; 
          wait(0.5);
       }
-      if(!BP1 && Rap_Cyc > ........){
-         Rap_Cyc = Rap_Cyc - ........;
-         moteur = Rap_Cyc; 
-         wait(0.5);
+      if(!BP2 && RegOut[0] > ....){
+         RegOut[0] = RegOut[0] - ....;
+         moteur = RegOut[0]/.........; 
+         wait(......);
       }
-      Led1 = ..................; 
+      Led1 = Pot.read(); 
       //**** 4 ****//
-      RegOut[0] = Rap_Cyc * ........;
       RegOut[1] = Pot.read() * .......;
       //**** 5 ****//
-      if(!BP1) BitsIn[0]  &=......;
-      else     BitsIn[0]  |=......;
-      if(!BP2) BitsIn[0]  &=......;
-      else     BitsIn[0]  |=......;
-      RegIn[0] = ....................;
+      if(Led2) BitsOut[0] |=.....;
+      else     BitsOut[0] &=.....;
+      if(BP1)  BitsIn[0]  |=.....;
+      else     BitsIn[0]  &=.....;
+      if(BP2)  BitsIn[0]  |=.....;
+      else     BitsIn[0]  &=.....;
+      RegIn[0] = Pot.read_u16();
    }
 }