programme course avec menu amélioré

Dependencies:   MMA8451Q mbed

Fork of Programme_course_2 by Freescale_Cachan

Revision:
0:3ec7fc598e48
Child:
2:a37de5eb8bf3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Mlib.cpp	Thu Jan 26 07:37:45 2017 +0000
@@ -0,0 +1,185 @@
+#include "Mlib.h"
+
+/***********AUTRES_FCT***************/
+
+char middle_3(char *tab)
+{
+    tri_a_bulle(tab, 3);
+    return tab[1];
+}
+
+int middle_3U(int *tab)
+{
+    tri_a_bulleU(tab, 3);
+    return tab[1];
+}
+
+float middle_3F(float *tab)
+{
+    
+    return tri_a_bulleF(tab, 3);
+}
+
+
+void tri_a_bulle(char* t, int const size) 
+{
+    int en_desordre = 1;
+    int i,j;
+
+    for (i = 0; (i < size) && en_desordre; ++i)
+    {
+        en_desordre = 0;
+        for (j = 1; j < (size - i); ++j)
+        {
+            if (t[j-1] > t[j])
+            {
+                int temp = t[j-1];
+                t[j-1] = t[j];
+                t[j] = temp;
+                en_desordre = 1;
+            }
+        }
+    }
+}
+void tri_a_bulleU(int* t, int const size) 
+{
+    int en_desordre = 1;
+    int i,j;
+
+    for (i = 0; (i < size) && en_desordre; ++i)
+    {
+        en_desordre = 0;
+        for (j = 1; j < (size - i); ++j)
+        {
+            if (t[j-1] > t[j])
+            {
+                int temp = t[j-1];
+                t[j-1] = t[j];
+                t[j] = temp;
+                en_desordre = 1;
+            }
+        }
+    }
+}
+float tri_a_bulleF(float* t2, int const size) 
+{
+    float t[3];
+    t[0] = t2[0];
+    t[1] = t2[1];
+    t[2] = t2[2];
+    
+        
+    int en_desordre = 1;
+    int i,j;
+
+    for (i = 0; (i < size) && en_desordre; ++i)
+    {
+        en_desordre = 0;
+        for (j = 1; j < (size - i); ++j)
+        {
+            if (t[j-1] > t[j])
+            {
+                float temp = t[j-1];
+                t[j-1] = t[j];
+                t[j] = temp;
+                en_desordre = 1;
+            }
+        }
+    }
+    return t[1];
+}
+
+unsigned char Moyenne(unsigned char *tab)
+{
+    int i = 0;
+    int somme = 0;
+    for(i = 0; i < 128;i++)
+    {
+        somme+=tab[i];
+    }
+    return somme/128.0;
+}
+char Moyenne2(char *tab, int nb)
+{
+    int i = 0;
+    int somme = 0;
+    for(i = 0; i < nb;i++)
+    {
+        somme+=tab[i];
+    }
+    return float(somme/nb);
+}
+
+void menu()
+{
+    static int p = 0;
+    p++;
+        wait(0.1);
+        if(BP2)
+        {
+            seuil_der++;
+            if(seuil_der == 2) seuil_der = -1;
+            led1 = 0;
+            wait(0.5);
+        }
+        if(seuil_der == 0)
+        {
+            led1 = p%2;
+        }
+        else if(seuil_der == 1)
+        {
+            led1 = 1;
+        }
+        else
+        {
+            led1 = 0;
+        }
+        if(S1 == 1)
+        {
+            led2 = 1;
+        }
+        else led2 = 0;
+        if(S2 == 1)
+        {
+            led3 = 1;
+        }
+        else led3= 0;
+}
+
+void fin_course()
+{
+    static int arr = 0;
+    if(somme_derivee >= (Moyenne2(last_five, 5) + (SEUIL_NB_DERRIVEE+5*seuil_der)) || arr != 0)
+    {
+        if(t_debut.read() > 3 && S1 == 1 && arr == 0)
+        {
+           arr = t_debut.read_ms();
+        }
+        else if(arr != 0 && t_debut.read_ms() > arr+100)
+        {
+            VIT = 0;
+        }
+    }
+    for(int j = 4; j > 0; j--)
+    {
+        last_five[j] = last_five[j-1];
+//                pc.printf("%d\n", last_five[j]);
+    }
+//            pc.printf("%d     |     %d\n", (somme_derivee), (Moyenne2(last_five, 5)));
+    last_five[0] = somme_derivee;
+}
+
+
+
+
+
+//void F_BalanceBlancs()
+//{
+//    unsigned char moy = 0;
+//    moy = Moyenne(cam_data);
+//    if(moy > LUMI_MOYENNE && tempsInte >= MIN_INTE) tempsInte-=INCREM_BALANCE;
+//    else if(tempsInte <= MAX_INTE) tempsInte+=INCREM_BALANCE;
+//}
+
+
+