programme course avec menu amélioré

Dependencies:   MMA8451Q mbed

Fork of Programme_course by Freescale_Cachan

Committer:
leandre
Date:
Wed Feb 01 13:41:24 2017 +0000
Revision:
1:000a03402c6e
Parent:
0:3ec7fc598e48
prog course avec menu am?lior?

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Freescale_cup 0:3ec7fc598e48 1 #include "Mlib.h"
Freescale_cup 0:3ec7fc598e48 2
Freescale_cup 0:3ec7fc598e48 3 /***********AUTRES_FCT***************/
Freescale_cup 0:3ec7fc598e48 4
Freescale_cup 0:3ec7fc598e48 5 char middle_3(char *tab)
Freescale_cup 0:3ec7fc598e48 6 {
Freescale_cup 0:3ec7fc598e48 7 tri_a_bulle(tab, 3);
Freescale_cup 0:3ec7fc598e48 8 return tab[1];
Freescale_cup 0:3ec7fc598e48 9 }
Freescale_cup 0:3ec7fc598e48 10
Freescale_cup 0:3ec7fc598e48 11 int middle_3U(int *tab)
Freescale_cup 0:3ec7fc598e48 12 {
Freescale_cup 0:3ec7fc598e48 13 tri_a_bulleU(tab, 3);
Freescale_cup 0:3ec7fc598e48 14 return tab[1];
Freescale_cup 0:3ec7fc598e48 15 }
Freescale_cup 0:3ec7fc598e48 16
Freescale_cup 0:3ec7fc598e48 17 float middle_3F(float *tab)
Freescale_cup 0:3ec7fc598e48 18 {
Freescale_cup 0:3ec7fc598e48 19
Freescale_cup 0:3ec7fc598e48 20 return tri_a_bulleF(tab, 3);
Freescale_cup 0:3ec7fc598e48 21 }
Freescale_cup 0:3ec7fc598e48 22
Freescale_cup 0:3ec7fc598e48 23
Freescale_cup 0:3ec7fc598e48 24 void tri_a_bulle(char* t, int const size)
Freescale_cup 0:3ec7fc598e48 25 {
Freescale_cup 0:3ec7fc598e48 26 int en_desordre = 1;
Freescale_cup 0:3ec7fc598e48 27 int i,j;
Freescale_cup 0:3ec7fc598e48 28
Freescale_cup 0:3ec7fc598e48 29 for (i = 0; (i < size) && en_desordre; ++i)
Freescale_cup 0:3ec7fc598e48 30 {
Freescale_cup 0:3ec7fc598e48 31 en_desordre = 0;
Freescale_cup 0:3ec7fc598e48 32 for (j = 1; j < (size - i); ++j)
Freescale_cup 0:3ec7fc598e48 33 {
Freescale_cup 0:3ec7fc598e48 34 if (t[j-1] > t[j])
Freescale_cup 0:3ec7fc598e48 35 {
Freescale_cup 0:3ec7fc598e48 36 int temp = t[j-1];
Freescale_cup 0:3ec7fc598e48 37 t[j-1] = t[j];
Freescale_cup 0:3ec7fc598e48 38 t[j] = temp;
Freescale_cup 0:3ec7fc598e48 39 en_desordre = 1;
Freescale_cup 0:3ec7fc598e48 40 }
Freescale_cup 0:3ec7fc598e48 41 }
Freescale_cup 0:3ec7fc598e48 42 }
Freescale_cup 0:3ec7fc598e48 43 }
Freescale_cup 0:3ec7fc598e48 44 void tri_a_bulleU(int* t, int const size)
Freescale_cup 0:3ec7fc598e48 45 {
Freescale_cup 0:3ec7fc598e48 46 int en_desordre = 1;
Freescale_cup 0:3ec7fc598e48 47 int i,j;
Freescale_cup 0:3ec7fc598e48 48
Freescale_cup 0:3ec7fc598e48 49 for (i = 0; (i < size) && en_desordre; ++i)
Freescale_cup 0:3ec7fc598e48 50 {
Freescale_cup 0:3ec7fc598e48 51 en_desordre = 0;
Freescale_cup 0:3ec7fc598e48 52 for (j = 1; j < (size - i); ++j)
Freescale_cup 0:3ec7fc598e48 53 {
Freescale_cup 0:3ec7fc598e48 54 if (t[j-1] > t[j])
Freescale_cup 0:3ec7fc598e48 55 {
Freescale_cup 0:3ec7fc598e48 56 int temp = t[j-1];
Freescale_cup 0:3ec7fc598e48 57 t[j-1] = t[j];
Freescale_cup 0:3ec7fc598e48 58 t[j] = temp;
Freescale_cup 0:3ec7fc598e48 59 en_desordre = 1;
Freescale_cup 0:3ec7fc598e48 60 }
Freescale_cup 0:3ec7fc598e48 61 }
Freescale_cup 0:3ec7fc598e48 62 }
Freescale_cup 0:3ec7fc598e48 63 }
Freescale_cup 0:3ec7fc598e48 64 float tri_a_bulleF(float* t2, int const size)
Freescale_cup 0:3ec7fc598e48 65 {
Freescale_cup 0:3ec7fc598e48 66 float t[3];
Freescale_cup 0:3ec7fc598e48 67 t[0] = t2[0];
Freescale_cup 0:3ec7fc598e48 68 t[1] = t2[1];
Freescale_cup 0:3ec7fc598e48 69 t[2] = t2[2];
Freescale_cup 0:3ec7fc598e48 70
Freescale_cup 0:3ec7fc598e48 71
Freescale_cup 0:3ec7fc598e48 72 int en_desordre = 1;
Freescale_cup 0:3ec7fc598e48 73 int i,j;
Freescale_cup 0:3ec7fc598e48 74
Freescale_cup 0:3ec7fc598e48 75 for (i = 0; (i < size) && en_desordre; ++i)
Freescale_cup 0:3ec7fc598e48 76 {
Freescale_cup 0:3ec7fc598e48 77 en_desordre = 0;
Freescale_cup 0:3ec7fc598e48 78 for (j = 1; j < (size - i); ++j)
Freescale_cup 0:3ec7fc598e48 79 {
Freescale_cup 0:3ec7fc598e48 80 if (t[j-1] > t[j])
Freescale_cup 0:3ec7fc598e48 81 {
Freescale_cup 0:3ec7fc598e48 82 float temp = t[j-1];
Freescale_cup 0:3ec7fc598e48 83 t[j-1] = t[j];
Freescale_cup 0:3ec7fc598e48 84 t[j] = temp;
Freescale_cup 0:3ec7fc598e48 85 en_desordre = 1;
Freescale_cup 0:3ec7fc598e48 86 }
Freescale_cup 0:3ec7fc598e48 87 }
Freescale_cup 0:3ec7fc598e48 88 }
Freescale_cup 0:3ec7fc598e48 89 return t[1];
Freescale_cup 0:3ec7fc598e48 90 }
Freescale_cup 0:3ec7fc598e48 91
Freescale_cup 0:3ec7fc598e48 92 unsigned char Moyenne(unsigned char *tab)
Freescale_cup 0:3ec7fc598e48 93 {
Freescale_cup 0:3ec7fc598e48 94 int i = 0;
Freescale_cup 0:3ec7fc598e48 95 int somme = 0;
Freescale_cup 0:3ec7fc598e48 96 for(i = 0; i < 128;i++)
Freescale_cup 0:3ec7fc598e48 97 {
Freescale_cup 0:3ec7fc598e48 98 somme+=tab[i];
Freescale_cup 0:3ec7fc598e48 99 }
Freescale_cup 0:3ec7fc598e48 100 return somme/128.0;
Freescale_cup 0:3ec7fc598e48 101 }
Freescale_cup 0:3ec7fc598e48 102 char Moyenne2(char *tab, int nb)
Freescale_cup 0:3ec7fc598e48 103 {
Freescale_cup 0:3ec7fc598e48 104 int i = 0;
Freescale_cup 0:3ec7fc598e48 105 int somme = 0;
Freescale_cup 0:3ec7fc598e48 106 for(i = 0; i < nb;i++)
Freescale_cup 0:3ec7fc598e48 107 {
Freescale_cup 0:3ec7fc598e48 108 somme+=tab[i];
Freescale_cup 0:3ec7fc598e48 109 }
Freescale_cup 0:3ec7fc598e48 110 return float(somme/nb);
Freescale_cup 0:3ec7fc598e48 111 }
Freescale_cup 0:3ec7fc598e48 112
Freescale_cup 0:3ec7fc598e48 113 void menu()
Freescale_cup 0:3ec7fc598e48 114 {
Freescale_cup 0:3ec7fc598e48 115 static int p = 0;
Freescale_cup 0:3ec7fc598e48 116 p++;
Freescale_cup 0:3ec7fc598e48 117 wait(0.1);
Freescale_cup 0:3ec7fc598e48 118 if(BP2)
Freescale_cup 0:3ec7fc598e48 119 {
Freescale_cup 0:3ec7fc598e48 120 seuil_der++;
Freescale_cup 0:3ec7fc598e48 121 if(seuil_der == 2) seuil_der = -1;
Freescale_cup 0:3ec7fc598e48 122 led1 = 0;
Freescale_cup 0:3ec7fc598e48 123 wait(0.5);
Freescale_cup 0:3ec7fc598e48 124 }
Freescale_cup 0:3ec7fc598e48 125 if(seuil_der == 0)
Freescale_cup 0:3ec7fc598e48 126 {
Freescale_cup 0:3ec7fc598e48 127 led1 = p%2;
Freescale_cup 0:3ec7fc598e48 128 }
Freescale_cup 0:3ec7fc598e48 129 else if(seuil_der == 1)
Freescale_cup 0:3ec7fc598e48 130 {
Freescale_cup 0:3ec7fc598e48 131 led1 = 1;
Freescale_cup 0:3ec7fc598e48 132 }
Freescale_cup 0:3ec7fc598e48 133 else
Freescale_cup 0:3ec7fc598e48 134 {
Freescale_cup 0:3ec7fc598e48 135 led1 = 0;
Freescale_cup 0:3ec7fc598e48 136 }
Freescale_cup 0:3ec7fc598e48 137 if(S1 == 1)
Freescale_cup 0:3ec7fc598e48 138 {
Freescale_cup 0:3ec7fc598e48 139 led2 = 1;
Freescale_cup 0:3ec7fc598e48 140 }
Freescale_cup 0:3ec7fc598e48 141 else led2 = 0;
Freescale_cup 0:3ec7fc598e48 142 if(S2 == 1)
Freescale_cup 0:3ec7fc598e48 143 {
Freescale_cup 0:3ec7fc598e48 144 led3 = 1;
Freescale_cup 0:3ec7fc598e48 145 }
Freescale_cup 0:3ec7fc598e48 146 else led3= 0;
Freescale_cup 0:3ec7fc598e48 147 }
Freescale_cup 0:3ec7fc598e48 148
Freescale_cup 0:3ec7fc598e48 149 void fin_course()
Freescale_cup 0:3ec7fc598e48 150 {
Freescale_cup 0:3ec7fc598e48 151 static int arr = 0;
Freescale_cup 0:3ec7fc598e48 152 if(somme_derivee >= (Moyenne2(last_five, 5) + (SEUIL_NB_DERRIVEE+5*seuil_der)) || arr != 0)
Freescale_cup 0:3ec7fc598e48 153 {
Freescale_cup 0:3ec7fc598e48 154 if(t_debut.read() > 3 && S1 == 1 && arr == 0)
Freescale_cup 0:3ec7fc598e48 155 {
Freescale_cup 0:3ec7fc598e48 156 arr = t_debut.read_ms();
Freescale_cup 0:3ec7fc598e48 157 }
Freescale_cup 0:3ec7fc598e48 158 else if(arr != 0 && t_debut.read_ms() > arr+100)
Freescale_cup 0:3ec7fc598e48 159 {
Freescale_cup 0:3ec7fc598e48 160 VIT = 0;
Freescale_cup 0:3ec7fc598e48 161 }
Freescale_cup 0:3ec7fc598e48 162 }
Freescale_cup 0:3ec7fc598e48 163 for(int j = 4; j > 0; j--)
Freescale_cup 0:3ec7fc598e48 164 {
Freescale_cup 0:3ec7fc598e48 165 last_five[j] = last_five[j-1];
Freescale_cup 0:3ec7fc598e48 166 // pc.printf("%d\n", last_five[j]);
Freescale_cup 0:3ec7fc598e48 167 }
Freescale_cup 0:3ec7fc598e48 168 // pc.printf("%d | %d\n", (somme_derivee), (Moyenne2(last_five, 5)));
Freescale_cup 0:3ec7fc598e48 169 last_five[0] = somme_derivee;
Freescale_cup 0:3ec7fc598e48 170 }
Freescale_cup 0:3ec7fc598e48 171
Freescale_cup 0:3ec7fc598e48 172
Freescale_cup 0:3ec7fc598e48 173
Freescale_cup 0:3ec7fc598e48 174
Freescale_cup 0:3ec7fc598e48 175
Freescale_cup 0:3ec7fc598e48 176 //void F_BalanceBlancs()
Freescale_cup 0:3ec7fc598e48 177 //{
Freescale_cup 0:3ec7fc598e48 178 // unsigned char moy = 0;
Freescale_cup 0:3ec7fc598e48 179 // moy = Moyenne(cam_data);
Freescale_cup 0:3ec7fc598e48 180 // if(moy > LUMI_MOYENNE && tempsInte >= MIN_INTE) tempsInte-=INCREM_BALANCE;
Freescale_cup 0:3ec7fc598e48 181 // else if(tempsInte <= MAX_INTE) tempsInte+=INCREM_BALANCE;
Freescale_cup 0:3ec7fc598e48 182 //}
Freescale_cup 0:3ec7fc598e48 183
Freescale_cup 0:3ec7fc598e48 184
Freescale_cup 0:3ec7fc598e48 185