![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
projet cabanis golf 2022
Dependencies: mbed HX711 TextLCD
main.cpp@3:e3f90a2684c1, 2022-06-20 (annotated)
- Committer:
- mbedyp
- Date:
- Mon Jun 20 09:37:37 2022 +0000
- Revision:
- 3:e3f90a2684c1
- Parent:
- 2:a7f75462252d
edit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mcragun | 0:5f789b9ae213 | 1 | #include "mbed.h" |
mcragun | 0:5f789b9ae213 | 2 | #include "HX711.h" |
mbedyp | 1:f6e3e0f785cd | 3 | #include "TextLCD.h" |
mbedyp | 1:f6e3e0f785cd | 4 | |
mbedyp | 1:f6e3e0f785cd | 5 | // LCD and Joystick Setting |
mbedyp | 1:f6e3e0f785cd | 6 | TextLCD lcd(p8, p10, p11, p5, p6, p7); // rs, e, d4-d7 |
mbedyp | 1:f6e3e0f785cd | 7 | //rs e d4 d5 d6 d7 |
mbedyp | 1:f6e3e0f785cd | 8 | DigitalOut RW(p9); |
mcragun | 0:5f789b9ae213 | 9 | |
mcragun | 0:5f789b9ae213 | 10 | DigitalOut gpo(D0); |
mbedyp | 1:f6e3e0f785cd | 11 | |
mbedyp | 1:f6e3e0f785cd | 12 | //LED MBED |
mbedyp | 1:f6e3e0f785cd | 13 | DigitalOut led1(LED1); |
mbedyp | 1:f6e3e0f785cd | 14 | DigitalOut led2(LED2); |
mbedyp | 1:f6e3e0f785cd | 15 | DigitalOut led3(LED3); |
mbedyp | 1:f6e3e0f785cd | 16 | DigitalOut led4(LED4); |
mbedyp | 1:f6e3e0f785cd | 17 | |
mbedyp | 1:f6e3e0f785cd | 18 | //LED BICOLORE |
mbedyp | 1:f6e3e0f785cd | 19 | DigitalOut ledB1(p29); // SI 1 LED ROUGE |
mbedyp | 1:f6e3e0f785cd | 20 | DigitalOut ledB2(p30); // SI 1 LED VERT |
mbedyp | 1:f6e3e0f785cd | 21 | |
mbedyp | 1:f6e3e0f785cd | 22 | //HX711 |
mbedyp | 1:f6e3e0f785cd | 23 | HX711 scale1(p22, p21); //22 , 21 |
mbedyp | 1:f6e3e0f785cd | 24 | HX711 scale2(p24, p23); //24 , 23 |
mbedyp | 1:f6e3e0f785cd | 25 | |
mbedyp | 1:f6e3e0f785cd | 26 | // BOUTON |
mbedyp | 1:f6e3e0f785cd | 27 | DigitalIn Up(p12); |
mbedyp | 1:f6e3e0f785cd | 28 | DigitalIn Down(p13); |
mbedyp | 1:f6e3e0f785cd | 29 | DigitalIn Left(p14); |
mbedyp | 1:f6e3e0f785cd | 30 | DigitalIn Right(p15); |
mbedyp | 1:f6e3e0f785cd | 31 | DigitalIn Center(p16); |
mcragun | 0:5f789b9ae213 | 32 | |
mbedyp | 2:a7f75462252d | 33 | //AnalogIn scaleRaw(A3); |
mbedyp | 1:f6e3e0f785cd | 34 | Serial pc(USBTX, USBRX); // USB Serial Terminal |
mbedyp | 3:e3f90a2684c1 | 35 | float calibration_factor1 = 2290; //2325 // -7050 worked for my 440lb max scale setup |
mbedyp | 3:e3f90a2684c1 | 36 | float calibration_factor2 = 2180; //2178 |
mbedyp | 1:f6e3e0f785cd | 37 | int averageSamples = 5; //NOMBRE DE MESURE |
mbedyp | 1:f6e3e0f785cd | 38 | |
mbedyp | 1:f6e3e0f785cd | 39 | int moyenneClick = 0; |
mbedyp | 1:f6e3e0f785cd | 40 | int boucleExecute = 0; |
mbedyp | 1:f6e3e0f785cd | 41 | |
mbedyp | 1:f6e3e0f785cd | 42 | int i = 0; //count |
mbedyp | 1:f6e3e0f785cd | 43 | |
mbedyp | 1:f6e3e0f785cd | 44 | float m = 0; //MASSE |
mbedyp | 1:f6e3e0f785cd | 45 | float lg = 0; //LG |
mbedyp | 1:f6e3e0f785cd | 46 | float MOI = 0; // MOI |
mbedyp | 1:f6e3e0f785cd | 47 | float massMoy = 0; //Moyenne de la masse a chaque points |
mbedyp | 1:f6e3e0f785cd | 48 | |
mbedyp | 1:f6e3e0f785cd | 49 | float weight1 = 0; // F1 |
mbedyp | 1:f6e3e0f785cd | 50 | float weight2 = 0; // F0 |
mbedyp | 1:f6e3e0f785cd | 51 | |
mbedyp | 1:f6e3e0f785cd | 52 | //SWINGWEIGHT |
mbedyp | 1:f6e3e0f785cd | 53 | float convertionInches = 2.54; // 1 inches = 2,54 centimètre |
mbedyp | 1:f6e3e0f785cd | 54 | float calculInches = 0; // Variable pour effectuer des calculs |
mbedyp | 1:f6e3e0f785cd | 55 | float SW = 0; // Variable résultat SWINGWEIGHT |
mbedyp | 1:f6e3e0f785cd | 56 | |
mbedyp | 1:f6e3e0f785cd | 57 | int main(void) { |
mbedyp | 1:f6e3e0f785cd | 58 | //Mettre la LED bicolore en ROUGE pendant la tare |
mbedyp | 1:f6e3e0f785cd | 59 | ledB1 = 1; |
mbedyp | 1:f6e3e0f785cd | 60 | ledB2 = 0; |
mbedyp | 1:f6e3e0f785cd | 61 | RW = 0; |
mbedyp | 1:f6e3e0f785cd | 62 | |
mbedyp | 1:f6e3e0f785cd | 63 | pc.printf("Starting Scale\n"); |
mbedyp | 1:f6e3e0f785cd | 64 | pc.printf("HX711 calibration sketch\n"); |
mbedyp | 1:f6e3e0f785cd | 65 | pc.printf("Retirer tout les poids des capteurs\n"); |
mbedyp | 1:f6e3e0f785cd | 66 | pc.printf("Une fois que la LED bicolore passe de rouge a verte placer le club\n"); |
mbedyp | 1:f6e3e0f785cd | 67 | pc.printf("[capteur1] Press 1 or a pour augmenter le facteur etalonnage de 25\n"); |
mbedyp | 1:f6e3e0f785cd | 68 | pc.printf("[capteur1] Press 3 or z pour diminuer le facteur etalonnage de 25\n"); |
mbedyp | 1:f6e3e0f785cd | 69 | pc.printf("[capteur2] Press 4 or a pour augmenter le facteur etalonnage de 25\n"); |
mbedyp | 1:f6e3e0f785cd | 70 | pc.printf("[capteur2] Press 6 or z pour diminuer le facteur etalonnage de 25\n"); |
mbedyp | 1:f6e3e0f785cd | 71 | |
mbedyp | 1:f6e3e0f785cd | 72 | scale1.setScale(0); |
mbedyp | 1:f6e3e0f785cd | 73 | scale1.tare(); //Reset the scale to 0 |
mbedyp | 1:f6e3e0f785cd | 74 | |
mbedyp | 1:f6e3e0f785cd | 75 | scale2.setScale(0); |
mbedyp | 1:f6e3e0f785cd | 76 | scale2.tare(); //Reset the scale to 0 |
mbedyp | 1:f6e3e0f785cd | 77 | |
mbedyp | 1:f6e3e0f785cd | 78 | long zero_factor1 = scale1.averageValue(averageSamples); //Get a baseline reading / Obtenez une lecture de base CAPTEUR 1 |
mbedyp | 1:f6e3e0f785cd | 79 | long zero_factor2 = scale2.averageValue(averageSamples); //Get a baseline reading / Obtenez une lecture de base CAPTEUR 2 |
mbedyp | 1:f6e3e0f785cd | 80 | pc.printf("Zero factor Capteur1: %.4f\n", zero_factor1); //This can be used to remove the need to tare the scale. Useful in permanent scale projects. / Cela peut être utilisé pour supprimer le besoin de tarer la balance. Utile dans les projets à échelle permanente. CAPTEUR 1 |
mbedyp | 1:f6e3e0f785cd | 81 | pc.printf("Zero factor Capteur2: %.4f\n", zero_factor2); //This can be used to remove the need to tare the scale. Useful in permanent scale projects. / Cela peut être utilisé pour supprimer le besoin de tarer la balance. Utile dans les projets à échelle permanente. CAPTEUR 2 |
mbedyp | 1:f6e3e0f785cd | 82 | |
mbedyp | 1:f6e3e0f785cd | 83 | // Mettre la LED en VERT pour indiquer la fin de la tare |
mbedyp | 1:f6e3e0f785cd | 84 | ledB1 = 0; |
mbedyp | 1:f6e3e0f785cd | 85 | ledB2 = 1; |
mbedyp | 1:f6e3e0f785cd | 86 | |
mbedyp | 1:f6e3e0f785cd | 87 | while (true) { |
mbedyp | 1:f6e3e0f785cd | 88 | scale1.setScale(calibration_factor1); //Adjust to this calibration factor / Ajuster à ce facteur d'étalonnage |
mbedyp | 1:f6e3e0f785cd | 89 | scale2.setScale(calibration_factor2); //Adjust to this calibration factor / Ajuster à ce facteur d'étalonnage |
mbedyp | 1:f6e3e0f785cd | 90 | |
mbedyp | 1:f6e3e0f785cd | 91 | if (moyenneClick == 0) { |
mbedyp | 1:f6e3e0f785cd | 92 | weight1 = scale1.getGram(); |
mbedyp | 1:f6e3e0f785cd | 93 | weight2 = scale2.getGram(); |
mbedyp | 1:f6e3e0f785cd | 94 | } |
mbedyp | 1:f6e3e0f785cd | 95 | |
mbedyp | 1:f6e3e0f785cd | 96 | //float raw = scaleRaw.read(); |
mbedyp | 1:f6e3e0f785cd | 97 | pc.printf("Reading Capteur1 g : %.2f\n", weight1); |
mbedyp | 1:f6e3e0f785cd | 98 | //pc.printf("Raw Value: %.7f\n", raw); |
mbedyp | 1:f6e3e0f785cd | 99 | pc.printf("Reading Capteur2 g : %.2f\n", weight2); |
mbedyp | 1:f6e3e0f785cd | 100 | |
mbedyp | 1:f6e3e0f785cd | 101 | m = weight1 - weight2; // Calcul masse du club |
mbedyp | 1:f6e3e0f785cd | 102 | lg = 45 * (weight1 / m); //Longueur jusqu'aux points d'équilibre |
mbedyp | 1:f6e3e0f785cd | 103 | |
mbedyp | 1:f6e3e0f785cd | 104 | MOI = m * (lg * lg); // Calcul masse du MOI (masse inertielle) |
mbedyp | 1:f6e3e0f785cd | 105 | |
mbedyp | 1:f6e3e0f785cd | 106 | calculInches = lg / convertionInches; //Convertion en inches |
mbedyp | 1:f6e3e0f785cd | 107 | SW = (calculInches - 14) * m; //Calcul SWINGWEIGHT |
mbedyp | 1:f6e3e0f785cd | 108 | |
mbedyp | 1:f6e3e0f785cd | 109 | switch (i) { |
mbedyp | 1:f6e3e0f785cd | 110 | case 0: { |
mbedyp | 1:f6e3e0f785cd | 111 | //LED_BOUTON_B |
mbedyp | 1:f6e3e0f785cd | 112 | ledB1 = 0; |
mbedyp | 1:f6e3e0f785cd | 113 | ledB2 = 1; |
mbedyp | 1:f6e3e0f785cd | 114 | |
mbedyp | 1:f6e3e0f785cd | 115 | lcd.cls(); //CLEAR LCD |
mbedyp | 1:f6e3e0f785cd | 116 | lcd.locate(0, 0); //Ecrire sur la 1er ligne |
mbedyp | 1:f6e3e0f785cd | 117 | lcd.printf("F1: %.2fg\n", weight1); // Afficher le poids en grammes du capteur 1 |
mbedyp | 1:f6e3e0f785cd | 118 | |
mbedyp | 1:f6e3e0f785cd | 119 | lcd.locate(0, 1); //Ecrire sur la 2ème ligne |
mbedyp | 1:f6e3e0f785cd | 120 | lcd.printf("F0: %.2fg\n", weight2); // Afficher le poids en grammes du capteur 2 |
mbedyp | 1:f6e3e0f785cd | 121 | |
mbedyp | 1:f6e3e0f785cd | 122 | if (!Center) { |
mbedyp | 1:f6e3e0f785cd | 123 | //CODE: LED_BOUTON_A |
mbedyp | 1:f6e3e0f785cd | 124 | ledB1 = 1; |
mbedyp | 1:f6e3e0f785cd | 125 | ledB2 = 0; |
mbedyp | 1:f6e3e0f785cd | 126 | |
mbedyp | 1:f6e3e0f785cd | 127 | weight1 = 0; |
mbedyp | 1:f6e3e0f785cd | 128 | weight2 = 0; |
mbedyp | 1:f6e3e0f785cd | 129 | |
mbedyp | 1:f6e3e0f785cd | 130 | wait(1.5); // Attendre 1.5 sec |
mbedyp | 1:f6e3e0f785cd | 131 | |
mbedyp | 1:f6e3e0f785cd | 132 | while (moyenneClick == 0) { |
mbedyp | 1:f6e3e0f785cd | 133 | |
mbedyp | 1:f6e3e0f785cd | 134 | boucleExecute++; |
mbedyp | 1:f6e3e0f785cd | 135 | |
mbedyp | 1:f6e3e0f785cd | 136 | weight1 = weight1 + scale1.getGram(); |
mbedyp | 1:f6e3e0f785cd | 137 | weight2 = weight2 + scale2.getGram(); |
mbedyp | 1:f6e3e0f785cd | 138 | |
mbedyp | 1:f6e3e0f785cd | 139 | m = weight1 - weight2; // Calcul masse du club |
mbedyp | 1:f6e3e0f785cd | 140 | |
mbedyp | 1:f6e3e0f785cd | 141 | massMoy = massMoy + m; |
mbedyp | 1:f6e3e0f785cd | 142 | |
mbedyp | 1:f6e3e0f785cd | 143 | wait(0.1); // Attendre 0.1 sec |
mbedyp | 1:f6e3e0f785cd | 144 | |
mbedyp | 1:f6e3e0f785cd | 145 | massMoy = massMoy / boucleExecute; |
mbedyp | 1:f6e3e0f785cd | 146 | |
mbedyp | 1:f6e3e0f785cd | 147 | lcd.cls(); //CLEAR LCD |
mbedyp | 1:f6e3e0f785cd | 148 | lcd.locate(0, 0); //Ecrire sur la 1er ligne |
mbedyp | 1:f6e3e0f785cd | 149 | lcd.printf("Nombre de points\n"); // Afficher le nombre de points |
mbedyp | 1:f6e3e0f785cd | 150 | |
mbedyp | 1:f6e3e0f785cd | 151 | lcd.locate(0, 1); //Ecrire sur la 1er ligne |
mbedyp | 1:f6e3e0f785cd | 152 | lcd.printf("%d m: %.2fg\n", boucleExecute, massMoy); // Afficher le nombre de points |
mbedyp | 1:f6e3e0f785cd | 153 | |
mbedyp | 1:f6e3e0f785cd | 154 | //LED VERT |
mbedyp | 1:f6e3e0f785cd | 155 | ledB1 = 0; |
mbedyp | 1:f6e3e0f785cd | 156 | ledB2 = 1; |
mbedyp | 1:f6e3e0f785cd | 157 | |
mbedyp | 1:f6e3e0f785cd | 158 | //LED ROUGE |
mbedyp | 1:f6e3e0f785cd | 159 | ledB1 = 1; |
mbedyp | 1:f6e3e0f785cd | 160 | ledB2 = 0; |
mbedyp | 1:f6e3e0f785cd | 161 | |
mbedyp | 1:f6e3e0f785cd | 162 | massMoy = 0; |
mbedyp | 1:f6e3e0f785cd | 163 | |
mbedyp | 1:f6e3e0f785cd | 164 | if (!Center) { |
mbedyp | 1:f6e3e0f785cd | 165 | //LED ROUGE |
mbedyp | 1:f6e3e0f785cd | 166 | ledB1 = 0; |
mbedyp | 1:f6e3e0f785cd | 167 | ledB2 = 1; |
mbedyp | 1:f6e3e0f785cd | 168 | moyenneClick = 1; //Mettre moyenneClick a 1 |
mbedyp | 1:f6e3e0f785cd | 169 | wait(1); // Attendre 1 sec |
mbedyp | 1:f6e3e0f785cd | 170 | } |
mbedyp | 1:f6e3e0f785cd | 171 | |
mbedyp | 1:f6e3e0f785cd | 172 | } |
mbedyp | 1:f6e3e0f785cd | 173 | |
mbedyp | 1:f6e3e0f785cd | 174 | weight1 = weight1 / boucleExecute; |
mbedyp | 1:f6e3e0f785cd | 175 | weight2 = weight2 / boucleExecute; |
mbedyp | 1:f6e3e0f785cd | 176 | |
mbedyp | 1:f6e3e0f785cd | 177 | wait(0.5); // Attendre 0.5 sec |
mbedyp | 1:f6e3e0f785cd | 178 | } else if (!Down) { |
mbedyp | 1:f6e3e0f785cd | 179 | i = 1; |
mbedyp | 1:f6e3e0f785cd | 180 | //CODE: LED_BOUTON_A |
mbedyp | 1:f6e3e0f785cd | 181 | ledB1 = 1; |
mbedyp | 1:f6e3e0f785cd | 182 | ledB2 = 0; |
mbedyp | 1:f6e3e0f785cd | 183 | |
mbedyp | 1:f6e3e0f785cd | 184 | wait(0.5); // Attendre 0.5 sec |
mbedyp | 1:f6e3e0f785cd | 185 | } else if (!Up) { |
mbedyp | 2:a7f75462252d | 186 | i = 4; |
mbedyp | 1:f6e3e0f785cd | 187 | //CODE: LED_BOUTON_A |
mbedyp | 1:f6e3e0f785cd | 188 | ledB1 = 1; |
mbedyp | 1:f6e3e0f785cd | 189 | ledB2 = 0; |
mbedyp | 1:f6e3e0f785cd | 190 | |
mbedyp | 1:f6e3e0f785cd | 191 | wait(0.5); // Attendre 0.5 sec |
mbedyp | 1:f6e3e0f785cd | 192 | } |
mbedyp | 1:f6e3e0f785cd | 193 | } |
mbedyp | 1:f6e3e0f785cd | 194 | break; |
mbedyp | 1:f6e3e0f785cd | 195 | |
mbedyp | 1:f6e3e0f785cd | 196 | case 1: { |
mbedyp | 1:f6e3e0f785cd | 197 | //LED_BOUTON_B |
mbedyp | 1:f6e3e0f785cd | 198 | ledB1 = 0; |
mbedyp | 1:f6e3e0f785cd | 199 | ledB2 = 1; |
mbedyp | 1:f6e3e0f785cd | 200 | |
mbedyp | 1:f6e3e0f785cd | 201 | lcd.cls(); //CLEAR LCD |
mbedyp | 1:f6e3e0f785cd | 202 | lcd.locate(0, 0); //Ecrire sur la 1er ligne |
mbedyp | 1:f6e3e0f785cd | 203 | lcd.printf("m = %.2fg\n", m); |
mcragun | 0:5f789b9ae213 | 204 | |
mbedyp | 1:f6e3e0f785cd | 205 | lg = 45 * (weight1 / m); |
mbedyp | 1:f6e3e0f785cd | 206 | lcd.locate(0, 1); //Ecrire sur la 2ème ligne |
mbedyp | 1:f6e3e0f785cd | 207 | lcd.printf("lg = %.2fcm\n", lg); |
mbedyp | 1:f6e3e0f785cd | 208 | |
mbedyp | 1:f6e3e0f785cd | 209 | if (!Down) { |
mbedyp | 1:f6e3e0f785cd | 210 | i = 2; |
mbedyp | 1:f6e3e0f785cd | 211 | //CODE: LED_BOUTON_A |
mbedyp | 1:f6e3e0f785cd | 212 | ledB1 = 1; |
mbedyp | 1:f6e3e0f785cd | 213 | ledB2 = 0; |
mbedyp | 1:f6e3e0f785cd | 214 | wait(0.5); // Attendre 0.5 sec |
mbedyp | 1:f6e3e0f785cd | 215 | } else if (!Up) { |
mbedyp | 1:f6e3e0f785cd | 216 | i = 0; |
mbedyp | 1:f6e3e0f785cd | 217 | //CODE: LED_BOUTON_A |
mbedyp | 1:f6e3e0f785cd | 218 | ledB1 = 1; |
mbedyp | 1:f6e3e0f785cd | 219 | ledB2 = 0; |
mbedyp | 1:f6e3e0f785cd | 220 | |
mbedyp | 1:f6e3e0f785cd | 221 | wait(0.5); // Attendre 0.5 sec |
mbedyp | 1:f6e3e0f785cd | 222 | } |
mbedyp | 1:f6e3e0f785cd | 223 | |
mbedyp | 1:f6e3e0f785cd | 224 | } |
mbedyp | 1:f6e3e0f785cd | 225 | break; |
mbedyp | 1:f6e3e0f785cd | 226 | |
mbedyp | 1:f6e3e0f785cd | 227 | case 2: { |
mbedyp | 1:f6e3e0f785cd | 228 | //LED_BOUTON_B |
mbedyp | 1:f6e3e0f785cd | 229 | ledB1 = 0; |
mbedyp | 1:f6e3e0f785cd | 230 | ledB2 = 1; |
mbedyp | 1:f6e3e0f785cd | 231 | |
mbedyp | 1:f6e3e0f785cd | 232 | lcd.cls(); //CLEAR LCD |
mbedyp | 1:f6e3e0f785cd | 233 | lcd.locate(0, 0); //Ecrire sur la 1er ligne |
mbedyp | 1:f6e3e0f785cd | 234 | lcd.printf("MOI:\n"); |
mbedyp | 1:f6e3e0f785cd | 235 | lcd.locate(0, 1); //Ecrire sur la 2ème ligne |
mbedyp | 1:f6e3e0f785cd | 236 | lcd.printf("%.2f kg.cm2\n", MOI / 1000); |
mbedyp | 1:f6e3e0f785cd | 237 | |
mbedyp | 1:f6e3e0f785cd | 238 | if (!Down) { |
mbedyp | 1:f6e3e0f785cd | 239 | i = 3; |
mbedyp | 1:f6e3e0f785cd | 240 | //CODE: LED_BOUTON_A |
mbedyp | 1:f6e3e0f785cd | 241 | ledB1 = 1; |
mbedyp | 1:f6e3e0f785cd | 242 | ledB2 = 0; |
mbedyp | 1:f6e3e0f785cd | 243 | |
mbedyp | 1:f6e3e0f785cd | 244 | wait(0.5); // Attendre 0.5 sec |
mbedyp | 1:f6e3e0f785cd | 245 | } else if (!Up) { |
mbedyp | 1:f6e3e0f785cd | 246 | i = 1; |
mbedyp | 1:f6e3e0f785cd | 247 | //CODE: LED_BOUTON_A |
mbedyp | 1:f6e3e0f785cd | 248 | ledB1 = 1; |
mbedyp | 1:f6e3e0f785cd | 249 | ledB2 = 0; |
mbedyp | 1:f6e3e0f785cd | 250 | |
mbedyp | 1:f6e3e0f785cd | 251 | wait(0.5); // Attendre 0.5 sec |
mbedyp | 1:f6e3e0f785cd | 252 | } |
mbedyp | 1:f6e3e0f785cd | 253 | } |
mbedyp | 1:f6e3e0f785cd | 254 | break; |
mbedyp | 1:f6e3e0f785cd | 255 | |
mbedyp | 1:f6e3e0f785cd | 256 | case 3: { |
mbedyp | 1:f6e3e0f785cd | 257 | //LED_BOUTON_B |
mbedyp | 1:f6e3e0f785cd | 258 | ledB1 = 0; |
mbedyp | 1:f6e3e0f785cd | 259 | ledB2 = 1; |
mbedyp | 1:f6e3e0f785cd | 260 | |
mbedyp | 1:f6e3e0f785cd | 261 | lcd.cls(); //CLEAR LCD |
mbedyp | 1:f6e3e0f785cd | 262 | lcd.locate(0, 0); //Ecrire sur la 1er ligne |
mbedyp | 1:f6e3e0f785cd | 263 | |
mbedyp | 1:f6e3e0f785cd | 264 | lcd.printf("SW = %.2f\n", SW); |
mbedyp | 1:f6e3e0f785cd | 265 | |
mbedyp | 1:f6e3e0f785cd | 266 | lcd.locate(0, 1); //Ecrire sur la 2ème ligne |
mbedyp | 1:f6e3e0f785cd | 267 | |
mbedyp | 1:f6e3e0f785cd | 268 | // Résultat de SW (SWINGWEIGHT / inertie) place le club dans une catégorie |
mbedyp | 1:f6e3e0f785cd | 269 | if (SW < 5250) { |
mbedyp | 1:f6e3e0f785cd | 270 | lcd.printf("SWINGWEIGHT NULL\n", SW); |
mbedyp | 1:f6e3e0f785cd | 271 | } else if (SW > 5250 && SW < 5300) { |
mbedyp | 1:f6e3e0f785cd | 272 | lcd.printf("SWINGWEIGHT = B4\n"); |
mbedyp | 1:f6e3e0f785cd | 273 | } else if (SW > 5300 && SW < 5350) { |
mbedyp | 1:f6e3e0f785cd | 274 | lcd.printf("SWINGWEIGHT = B5\n"); |
mbedyp | 1:f6e3e0f785cd | 275 | } else if (SW > 5350 && SW < 5400) { |
mbedyp | 1:f6e3e0f785cd | 276 | lcd.printf("SWINGWEIGHT = B6\n"); |
mbedyp | 1:f6e3e0f785cd | 277 | } else if (SW > 5400 && SW < 5450) { |
mbedyp | 1:f6e3e0f785cd | 278 | lcd.printf("SWINGWEIGHT = B7\n"); |
mbedyp | 1:f6e3e0f785cd | 279 | } else if (SW > 5450 && SW < 5500) { |
mbedyp | 1:f6e3e0f785cd | 280 | lcd.printf("SWINGWEIGHT = B8\n"); |
mbedyp | 1:f6e3e0f785cd | 281 | } else if (SW > 5500 && SW < 5550) { |
mbedyp | 1:f6e3e0f785cd | 282 | lcd.printf("SWINGWEIGHT = B9\n"); |
mbedyp | 1:f6e3e0f785cd | 283 | } else if (SW > 5550 && SW < 5600) { |
mbedyp | 1:f6e3e0f785cd | 284 | lcd.printf("SWINGWEIGHT = C0\n"); |
mbedyp | 1:f6e3e0f785cd | 285 | } else if (SW > 5600 && SW < 5650) { |
mbedyp | 1:f6e3e0f785cd | 286 | lcd.printf("SWINGWEIGHT = C1\n"); |
mbedyp | 1:f6e3e0f785cd | 287 | } else if (SW > 5650 && SW < 5700) { |
mbedyp | 1:f6e3e0f785cd | 288 | lcd.printf("SWINGWEIGHT = C2\n"); |
mbedyp | 1:f6e3e0f785cd | 289 | } else if (SW > 5700 && SW < 5750) { |
mbedyp | 1:f6e3e0f785cd | 290 | lcd.printf("SWINGWEIGHT = C3\n"); |
mbedyp | 1:f6e3e0f785cd | 291 | } else if (SW > 5750 && SW < 5800) { |
mbedyp | 1:f6e3e0f785cd | 292 | lcd.printf("SWINGWEIGHT = C4\n"); |
mbedyp | 1:f6e3e0f785cd | 293 | } else if (SW > 5800 && SW < 5850) { |
mbedyp | 1:f6e3e0f785cd | 294 | lcd.printf("SWINGWEIGHT = C5\n"); |
mbedyp | 1:f6e3e0f785cd | 295 | } else if (SW > 5850 && SW < 5900) { |
mbedyp | 1:f6e3e0f785cd | 296 | lcd.printf("SWINGWEIGHT = C6\n"); |
mbedyp | 1:f6e3e0f785cd | 297 | } else if (SW > 5900 && SW < 5950) { |
mbedyp | 1:f6e3e0f785cd | 298 | lcd.printf("SWINGWEIGHT = C7\n"); |
mbedyp | 1:f6e3e0f785cd | 299 | } else if (SW > 5950 && SW < 6000) { |
mbedyp | 1:f6e3e0f785cd | 300 | lcd.printf("SWINGWEIGHT = C8\n"); |
mbedyp | 1:f6e3e0f785cd | 301 | } else if (SW > 6000 && SW < 6050) { |
mbedyp | 1:f6e3e0f785cd | 302 | lcd.printf("SWINGWEIGHT = C9\n"); |
mbedyp | 1:f6e3e0f785cd | 303 | } else if (SW > 6050 && SW < 6100) { |
mbedyp | 1:f6e3e0f785cd | 304 | lcd.printf("SWINGWEIGHT = D0\n"); |
mbedyp | 1:f6e3e0f785cd | 305 | } else if (SW > 6100 && SW < 6150) { |
mbedyp | 1:f6e3e0f785cd | 306 | lcd.printf("SWINGWEIGHT = D1\n"); |
mbedyp | 1:f6e3e0f785cd | 307 | } else if (SW > 6150 && SW < 6200) { |
mbedyp | 1:f6e3e0f785cd | 308 | lcd.printf("SWINGWEIGHT = D2\n"); |
mbedyp | 1:f6e3e0f785cd | 309 | } else if (SW > 6200 && SW < 6250) { |
mbedyp | 1:f6e3e0f785cd | 310 | lcd.printf("SWINGWEIGHT = D3\n"); |
mbedyp | 1:f6e3e0f785cd | 311 | } else if (SW > 6250 && SW < 6300) { |
mbedyp | 1:f6e3e0f785cd | 312 | lcd.printf("SWINGWEIGHT = D4\n"); |
mbedyp | 1:f6e3e0f785cd | 313 | } else if (SW > 6300 && SW < 6350) { |
mbedyp | 1:f6e3e0f785cd | 314 | lcd.printf("SWINGWEIGHT = D5\n"); |
mbedyp | 1:f6e3e0f785cd | 315 | } else if (SW > 6350 && SW < 6400) { |
mbedyp | 1:f6e3e0f785cd | 316 | lcd.printf("SWINGWEIGHT = D6\n"); |
mbedyp | 1:f6e3e0f785cd | 317 | } else if (SW > 6400 && SW < 6450) { |
mbedyp | 1:f6e3e0f785cd | 318 | lcd.printf("SWINGWEIGHT = D7\n"); |
mbedyp | 1:f6e3e0f785cd | 319 | } else if (SW > 6450 && SW < 6500) { |
mbedyp | 1:f6e3e0f785cd | 320 | lcd.printf("SWINGWEIGHT = D8\n"); |
mbedyp | 1:f6e3e0f785cd | 321 | } else if (SW > 6500) { |
mbedyp | 1:f6e3e0f785cd | 322 | lcd.printf("SWINGWEIGHT = D9\n"); |
mbedyp | 1:f6e3e0f785cd | 323 | } |
mbedyp | 1:f6e3e0f785cd | 324 | |
mbedyp | 1:f6e3e0f785cd | 325 | if (!Down) { |
mbedyp | 1:f6e3e0f785cd | 326 | i = 4; |
mbedyp | 1:f6e3e0f785cd | 327 | //CODE: LED_BOUTON_A |
mbedyp | 1:f6e3e0f785cd | 328 | ledB1 = 1; |
mbedyp | 1:f6e3e0f785cd | 329 | ledB2 = 0; |
mbedyp | 1:f6e3e0f785cd | 330 | |
mbedyp | 1:f6e3e0f785cd | 331 | wait(0.5); // Attendre 0.5 sec |
mbedyp | 1:f6e3e0f785cd | 332 | } else if (!Up) { |
mbedyp | 1:f6e3e0f785cd | 333 | i = 2; |
mbedyp | 1:f6e3e0f785cd | 334 | //CODE: LED_BOUTON_A |
mbedyp | 1:f6e3e0f785cd | 335 | ledB1 = 1; |
mbedyp | 1:f6e3e0f785cd | 336 | ledB2 = 0; |
mbedyp | 1:f6e3e0f785cd | 337 | |
mbedyp | 1:f6e3e0f785cd | 338 | wait(0.5); // Attendre 0.5 sec |
mbedyp | 1:f6e3e0f785cd | 339 | } |
mbedyp | 1:f6e3e0f785cd | 340 | } |
mbedyp | 1:f6e3e0f785cd | 341 | break; |
mbedyp | 1:f6e3e0f785cd | 342 | |
mbedyp | 1:f6e3e0f785cd | 343 | case 4: { |
mbedyp | 1:f6e3e0f785cd | 344 | //LED_BOUTON_B |
mbedyp | 1:f6e3e0f785cd | 345 | ledB1 = 0; |
mbedyp | 1:f6e3e0f785cd | 346 | ledB2 = 1; |
mbedyp | 1:f6e3e0f785cd | 347 | |
mbedyp | 1:f6e3e0f785cd | 348 | lcd.cls(); //CLEAR LCD |
mbedyp | 1:f6e3e0f785cd | 349 | lcd.locate(0, 0); //Ecrire sur la 1er ligne |
mbedyp | 1:f6e3e0f785cd | 350 | |
mbedyp | 1:f6e3e0f785cd | 351 | lcd.printf("N points moyenne"); |
mbedyp | 1:f6e3e0f785cd | 352 | |
mbedyp | 1:f6e3e0f785cd | 353 | lcd.locate(0, 1); //Ecrire sur la 2eme ligne |
mbedyp | 1:f6e3e0f785cd | 354 | lcd.printf("%d\n", boucleExecute); |
mbedyp | 1:f6e3e0f785cd | 355 | |
mbedyp | 1:f6e3e0f785cd | 356 | if (!Down) { |
mbedyp | 1:f6e3e0f785cd | 357 | i = 0; |
mbedyp | 1:f6e3e0f785cd | 358 | //CODE: LED_BOUTON_A |
mbedyp | 1:f6e3e0f785cd | 359 | ledB1 = 1; |
mbedyp | 1:f6e3e0f785cd | 360 | ledB2 = 0; |
mbedyp | 1:f6e3e0f785cd | 361 | |
mbedyp | 1:f6e3e0f785cd | 362 | wait(0.5); // Attendre 0.5 sec |
mbedyp | 1:f6e3e0f785cd | 363 | } else if (!Up) { |
mbedyp | 1:f6e3e0f785cd | 364 | i = 3; |
mbedyp | 1:f6e3e0f785cd | 365 | //CODE: LED_BOUTON_A |
mbedyp | 1:f6e3e0f785cd | 366 | ledB1 = 1; |
mbedyp | 1:f6e3e0f785cd | 367 | ledB2 = 0; |
mbedyp | 1:f6e3e0f785cd | 368 | |
mbedyp | 1:f6e3e0f785cd | 369 | wait(0.5); // Attendre 0.5 sec |
mbedyp | 1:f6e3e0f785cd | 370 | } |
mbedyp | 1:f6e3e0f785cd | 371 | } |
mbedyp | 1:f6e3e0f785cd | 372 | break; |
mbedyp | 2:a7f75462252d | 373 | }// FIN SWITCH |
mbedyp | 1:f6e3e0f785cd | 374 | /* |
mbedyp | 1:f6e3e0f785cd | 375 | CODE INFORMATION: |
mbedyp | 1:f6e3e0f785cd | 376 | LED_BOUTON_A: Mettre la LED bicolore en ROUGE pour que l'utilisateur sache que son action a était pris en compte |
mbedyp | 1:f6e3e0f785cd | 377 | LED_BOUTON_B: Mettre la LED bicolore en VERT à la fin de l'action utilisateur |
mcragun | 0:5f789b9ae213 | 378 | |
mbedyp | 1:f6e3e0f785cd | 379 | */ |
mcragun | 0:5f789b9ae213 | 380 | |
mbedyp | 1:f6e3e0f785cd | 381 | if (pc.readable()) { |
mbedyp | 1:f6e3e0f785cd | 382 | char temp = pc.getc(); |
mbedyp | 1:f6e3e0f785cd | 383 | if (temp == '1' || temp == 'a') |
mbedyp | 1:f6e3e0f785cd | 384 | calibration_factor1 -= 25; |
mbedyp | 1:f6e3e0f785cd | 385 | else if (temp == '3' || temp == 'z') |
mbedyp | 1:f6e3e0f785cd | 386 | calibration_factor1 += 25; |
mbedyp | 1:f6e3e0f785cd | 387 | else if (temp == '4' || temp == 'q') |
mbedyp | 1:f6e3e0f785cd | 388 | calibration_factor2 -= 25; |
mbedyp | 1:f6e3e0f785cd | 389 | else if (temp == '6' || temp == 's') |
mbedyp | 1:f6e3e0f785cd | 390 | calibration_factor2 += 25; |
mcragun | 0:5f789b9ae213 | 391 | } |
mbedyp | 1:f6e3e0f785cd | 392 | gpo = !gpo; // toggle pin |
mbedyp | 1:f6e3e0f785cd | 393 | wait(0.2); // Attendre 0.2 sec |
mbedyp | 2:a7f75462252d | 394 | }// FIN WHILE |
mbedyp | 2:a7f75462252d | 395 | }// FIN MAIN |