7Robot_Freescale / Mbed 2 deprecated freescal_cup_k22f

Dependencies:   mbed freescal_cup_k22f

Dependents:   freescal_cup_k22f

Revision:
22:b5a3688e144b
Parent:
21:9430357e777c
Child:
23:fa834aa184e0
--- a/source/main.cpp	Sat Jan 17 17:45:52 2015 +0000
+++ b/source/main.cpp	Sat Jan 17 18:06:33 2015 +0000
@@ -22,8 +22,8 @@
     int indexMax=127;
     int compteur_uart=0;
     int max_detect1=indexMin;
-    int max_detect2=indexMin;
-    int max_detect=(max_detect1+max_detect2)/2;
+    int min_detect2=indexMin;
+    int max_detect=(max_detect1+min_detect2)/2;
     float Kp_servo = 0;
     uart.baud(115200); 
     init_led();
@@ -35,8 +35,8 @@
     while(1){
         
         readline();
-        passebas(12);
-        //derivation();
+        passebas(10);
+        derivation();
         //passebas(4); 
            
            
@@ -61,18 +61,24 @@
         compteur_uart =compteur_uart+1;  
         }
         
+        max_detect1=indexMin;
+        min_detect2=indexMin;
+        
         for (int j=indexMin; j<=indexMax; j++)
         {
-            if (pixel1[j]>pixel1[max_detect])
+            if (pixel1[j]>pixel1[max_detect1])
             {
                 max_detect1=j;
             }
-            if (pixel1[j]>pixel2[max_detect])
+        }  
+        for (int j=indexMin; j<=indexMax; j++)
+        {      
+            if (pixel1[j]<pixel2[min_detect2])
             {
-                max_detect2=j;
+                min_detect2=j;
             }    
         }  
-        max_detect=(max_detect1+max_detect2)/2; 
+        max_detect=(max_detect1+min_detect2)/2; 
         // Réduction proportionelle de la vitesse moteur si l'angle du servo augmente
         if (max_detect>64)
         {