maxime bouillot / Mbed 2 deprecated testLucadeTHmaxBOUI

Dependencies:   LCD_DISCO_F429ZI mbed BSP_DISCO_F429ZI

Revision:
19:09ad3ca689f3
Parent:
18:1864979c9b3c
Child:
20:f3e8319b7899
diff -r 1864979c9b3c -r 09ad3ca689f3 ClickClickClouk/codeurRotatifRelatif.cpp
--- a/ClickClickClouk/codeurRotatifRelatif.cpp	Sun Apr 28 11:25:43 2019 +0000
+++ b/ClickClickClouk/codeurRotatifRelatif.cpp	Mon Apr 29 16:34:28 2019 +0000
@@ -1,43 +1,23 @@
 #include "codeurRotatifRelatif.h"
 #include <mbed.h>
 
-/*int CdRelatif(void){
-    DigitalIn pinClick(PG_2); 
-    DigitalIn pinRot1(PG_3);
-    DigitalIn pinRot2(PG_9);
-    int actA; //def des variables
-    int actB;
-    int actOldA=0;
-    //int actOldB=0;
-    while(!pinClick.read()){ //on attent un résultat
-        actA=!pinRot1.read(); //On lit ce qui se passe aux bornes du codeur
-        actB=!pinRot2.read();
-        if(actA && actB){ //un truc se passe
-            int r = 1 - 2 * actOldA; //dans un sens on a 1, dans l'autre on a -1
-            return r;
-        }
-        actOldA=actA;
-        //actOldB=actB;
-    }
-    return 0;
-}*/
-
 int CdRelatif(void){
     DigitalIn pinClick(PG_2); 
     DigitalIn pinRot1(PG_3);
     DigitalIn pinRot2(PG_9);
     int actA; //def des variables
     int actB;
+    int actOldA=0;
+    int actOldB=0;
     while(!pinClick.read()){ //on attent un résultat
-         //On lit ce qui se passe aux bornes du codeur
-        actB=!pinRot2.read();
-        actA=!pinRot1.read();
-        if(actA || actB){ //un truc se passe
-                    int r = 1 - 2 * actA; //dans un sens on a 1, dans l'autre on a -1
-                    return r;
-                
-            
+        actB=!pinRot1.read(); //On lit ce qui se passe aux bornes du codeur
+        actA=!pinRot2.read();
+        if(actA && actB){ //un truc se passe
+            int r = 1 - 2 * actOldA; //dans un sens on a 1, dans l'autre on a -1
+            return r;
         }
+        actOldA=actA || actOldA;
+        actOldB=actB || actOldB;
     }
     return 0;
 }
@@ -45,13 +25,13 @@
 void cRR_test(void){
     LCD_DISCO_F429ZI lcdTemp;
     lcdTemp.Clear(LCD_COLOR_BLUE);
-    for(ever){
+    /*for(ever){
         lcdTemp.Clear(LCD_COLOR_BLUE);
         int val=CdRelatif();
         BS_displayChiffre(50,50,val,4,LCD_COLOR_WHITE);
         wait(1);
-    }
-    /*int a=0;
+    }*/
+    int a=0;
     for(ever){
         lcdTemp.Clear(LCD_COLOR_BLUE);
         int val=CdRelatif();
@@ -62,5 +42,5 @@
             BS_displayChiffreClean(150,150,val,4,LCD_COLOR_WHITE,LCD_COLOR_BLUE);
             wait(1);
         }
-    }*/
+    }
 }