float impossible dans RPC donc weight1 et 2 en float > f0 et f1 en int pour sa: f0 = (int) weight1;....
Dependencies: mbed HTTPServer EthernetNetIf HX711 TextLCD RPCInterface
HTTPServerExample.cpp@6:2aba0ce3dedd, 2022-06-11 (annotated)
- Committer:
- mbedyp
- Date:
- Sat Jun 11 22:21:00 2022 +0000
- Revision:
- 6:2aba0ce3dedd
- Parent:
- 5:3754211a1b5b
float impossible dans RPC donc weight1 et 2 en float > f0 et f1 en int; pour sa: f0 = (int) weight1;....
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
donatien | 0:0b1369ae8b74 | 1 | #include "mbed.h" |
donatien | 0:0b1369ae8b74 | 2 | #include "EthernetNetIf.h" |
donatien | 0:0b1369ae8b74 | 3 | #include "HTTPServer.h" |
LouisReynier | 3:c2b64cce42d8 | 4 | #include "SerialRPCInterface.h" |
tostestas19 | 5:3754211a1b5b | 5 | #include "HX711.h" |
tostestas19 | 5:3754211a1b5b | 6 | #include "TextLCD.h" |
tostestas19 | 5:3754211a1b5b | 7 | |
tostestas19 | 5:3754211a1b5b | 8 | #define BLINKING_RATE 0.5 |
tostestas19 | 5:3754211a1b5b | 9 | #define temps_on 0.5 |
LouisReynier | 3:c2b64cce42d8 | 10 | |
LouisReynier | 3:c2b64cce42d8 | 11 | // LR 2/2/17 |
LouisReynier | 3:c2b64cce42d8 | 12 | // sur ce fichier j'ai rajouté une variable RPC count que je peux lire à distance |
LouisReynier | 3:c2b64cce42d8 | 13 | // adresse/rpc/count/read/ |
donatien | 0:0b1369ae8b74 | 14 | |
tostestas19 | 5:3754211a1b5b | 15 | // LCD and Joystick Setting |
tostestas19 | 5:3754211a1b5b | 16 | TextLCD lcd(p8, p10, p11, p5, p6, p7); // rs, e, d4-d7 |
tostestas19 | 5:3754211a1b5b | 17 | //rs e d4 d5 d6 d7 |
mbedyp | 6:2aba0ce3dedd | 18 | DigitalOut RW(p9); |
tostestas19 | 5:3754211a1b5b | 19 | |
mbedyp | 6:2aba0ce3dedd | 20 | //LED MBED |
tostestas19 | 5:3754211a1b5b | 21 | DigitalOut led1(LED1); |
tostestas19 | 5:3754211a1b5b | 22 | DigitalOut led2(LED2); |
tostestas19 | 5:3754211a1b5b | 23 | DigitalOut led3(LED3); |
tostestas19 | 5:3754211a1b5b | 24 | DigitalOut led4(LED4); |
tostestas19 | 5:3754211a1b5b | 25 | |
mbedyp | 6:2aba0ce3dedd | 26 | //LED BICOLORE |
mbedyp | 6:2aba0ce3dedd | 27 | DigitalOut ledB1(p29); // SI 1 LED ROUGE |
mbedyp | 6:2aba0ce3dedd | 28 | DigitalOut ledB2(p30); // SI 1 LED VERT |
mbedyp | 6:2aba0ce3dedd | 29 | |
tostestas19 | 4:5b29715e0aaa | 30 | //AnalogIn Pot1(p19, "pot1"); |
tostestas19 | 4:5b29715e0aaa | 31 | //AnalogIn Pot2(p20, "pot2"); |
LouisReynier | 3:c2b64cce42d8 | 32 | |
tostestas19 | 5:3754211a1b5b | 33 | |
tostestas19 | 5:3754211a1b5b | 34 | // BOUTON |
tostestas19 | 5:3754211a1b5b | 35 | DigitalIn Up(p12); |
tostestas19 | 5:3754211a1b5b | 36 | DigitalIn Down(p13); |
tostestas19 | 5:3754211a1b5b | 37 | DigitalIn Left(p14); |
tostestas19 | 5:3754211a1b5b | 38 | DigitalIn Right(p15); |
tostestas19 | 5:3754211a1b5b | 39 | DigitalIn Center(p16); |
tostestas19 | 5:3754211a1b5b | 40 | |
tostestas19 | 5:3754211a1b5b | 41 | //HX711 |
tostestas19 | 5:3754211a1b5b | 42 | HX711 scale1(p22, p21); //22 , 21 |
tostestas19 | 5:3754211a1b5b | 43 | HX711 scale2(p24, p23); //24 , 23 |
tostestas19 | 5:3754211a1b5b | 44 | |
tostestas19 | 5:3754211a1b5b | 45 | |
LouisReynier | 3:c2b64cce42d8 | 46 | int count = 0 ; |
tostestas19 | 4:5b29715e0aaa | 47 | //int F1 = 0 ; |
tostestas19 | 4:5b29715e0aaa | 48 | //int F2 = 0 ; |
tostestas19 | 4:5b29715e0aaa | 49 | |
tostestas19 | 4:5b29715e0aaa | 50 | |
tostestas19 | 5:3754211a1b5b | 51 | //int pot1 ; a renplacer |
tostestas19 | 5:3754211a1b5b | 52 | //int pot2; a remplacer |
tostestas19 | 5:3754211a1b5b | 53 | |
tostestas19 | 5:3754211a1b5b | 54 | float calibration_factor1 = 2325; //2325 // -7050 worked for my 440lb max scale setup |
tostestas19 | 5:3754211a1b5b | 55 | float calibration_factor2 = 2178; //2178 |
tostestas19 | 5:3754211a1b5b | 56 | int averageSamples = 5; //NOMBRE DE MESURE |
mbedyp | 6:2aba0ce3dedd | 57 | |
mbedyp | 6:2aba0ce3dedd | 58 | int moyenneClick = 0; |
mbedyp | 6:2aba0ce3dedd | 59 | int boucleExecute = 0; |
mbedyp | 6:2aba0ce3dedd | 60 | |
mbedyp | 6:2aba0ce3dedd | 61 | int menu = 0; |
mbedyp | 6:2aba0ce3dedd | 62 | |
mbedyp | 6:2aba0ce3dedd | 63 | float m = 0; //MASSE en g |
mbedyp | 6:2aba0ce3dedd | 64 | float lg = 0; //LG en cm |
mbedyp | 6:2aba0ce3dedd | 65 | float MOI = 0; // MOI en kg*cm2 |
mbedyp | 6:2aba0ce3dedd | 66 | float massMoy = 0; //Moyenne de la masse a chaque points |
mbedyp | 6:2aba0ce3dedd | 67 | |
mbedyp | 6:2aba0ce3dedd | 68 | float weight1 = 0; // F0 |
mbedyp | 6:2aba0ce3dedd | 69 | float weight2 = 0; // F1 |
mbedyp | 6:2aba0ce3dedd | 70 | |
mbedyp | 6:2aba0ce3dedd | 71 | int f0 = 0; |
mbedyp | 6:2aba0ce3dedd | 72 | int f1 = 0; |
mbedyp | 6:2aba0ce3dedd | 73 | |
mbedyp | 6:2aba0ce3dedd | 74 | //SWINGWEIGHT |
mbedyp | 6:2aba0ce3dedd | 75 | float convertionInches = 2.54; // 1 inches = 2,54 centimètre |
mbedyp | 6:2aba0ce3dedd | 76 | float calculInches = 0; // Variable pour effectuer des calculs |
mbedyp | 6:2aba0ce3dedd | 77 | float SW = 0; // Variable résultat SWINGWEIGHT |
tostestas19 | 5:3754211a1b5b | 78 | |
tostestas19 | 5:3754211a1b5b | 79 | RPCVariable<int> rpc_f0(&f0, "f0"); |
tostestas19 | 5:3754211a1b5b | 80 | RPCVariable<int> rpc_f1(&f1, "f1"); |
tostestas19 | 4:5b29715e0aaa | 81 | |
tostestas19 | 4:5b29715e0aaa | 82 | |
LouisReynier | 3:c2b64cce42d8 | 83 | RPCVariable<int> rpc_count(&count, "count"); |
donatien | 0:0b1369ae8b74 | 84 | LocalFileSystem fs("webfs"); |
donatien | 0:0b1369ae8b74 | 85 | |
donatien | 0:0b1369ae8b74 | 86 | EthernetNetIf eth; |
donatien | 0:0b1369ae8b74 | 87 | HTTPServer svr; |
donatien | 0:0b1369ae8b74 | 88 | |
mbedyp | 6:2aba0ce3dedd | 89 | int main() { |
tostestas19 | 5:3754211a1b5b | 90 | |
mbedyp | 6:2aba0ce3dedd | 91 | //Mettre la LED bicolore en ROUGE pendant la tare |
mbedyp | 6:2aba0ce3dedd | 92 | ledB1 = 1; |
mbedyp | 6:2aba0ce3dedd | 93 | ledB2 = 0; |
mbedyp | 6:2aba0ce3dedd | 94 | RW = 0; |
tostestas19 | 4:5b29715e0aaa | 95 | |
mbedyp | 6:2aba0ce3dedd | 96 | scale1.setScale(0); |
mbedyp | 6:2aba0ce3dedd | 97 | scale1.tare(); //Reset the scale to 0 |
mbedyp | 6:2aba0ce3dedd | 98 | |
mbedyp | 6:2aba0ce3dedd | 99 | scale2.setScale(0); |
mbedyp | 6:2aba0ce3dedd | 100 | scale2.tare(); //Reset the scale to 0 |
mbedyp | 6:2aba0ce3dedd | 101 | |
mbedyp | 6:2aba0ce3dedd | 102 | long zero_factor1 = scale1.averageValue(averageSamples); //Get a baseline reading / Obtenez une lecture de base CAPTEUR 1 |
mbedyp | 6:2aba0ce3dedd | 103 | long zero_factor2 = scale2.averageValue(averageSamples); //Get a baseline reading / Obtenez une lecture de base CAPTEUR 2 |
mbedyp | 6:2aba0ce3dedd | 104 | |
donatien | 0:0b1369ae8b74 | 105 | Base::add_rpc_class<DigitalOut>(); |
donatien | 0:0b1369ae8b74 | 106 | |
donatien | 1:114e347434c1 | 107 | printf("Setting up...\n"); |
LouisReynier | 3:c2b64cce42d8 | 108 | |
tostestas19 | 4:5b29715e0aaa | 109 | // modif LR config IP manuelle sinon dhcp |
tostestas19 | 4:5b29715e0aaa | 110 | /* |
tostestas19 | 4:5b29715e0aaa | 111 | EthernetNetIf eth( IpAddr(10,119,24,230), // IP |
tostestas19 | 4:5b29715e0aaa | 112 | IpAddr(255,255,252,0), // Subnet mask |
tostestas19 | 4:5b29715e0aaa | 113 | IpAddr(10,119,24,245), // Gateway |
tostestas19 | 4:5b29715e0aaa | 114 | IpAddr(10,119,24,245) ); // DNS |
LouisReynier | 3:c2b64cce42d8 | 115 | |
tostestas19 | 4:5b29715e0aaa | 116 | */ |
donatien | 0:0b1369ae8b74 | 117 | EthernetErr ethErr = eth.setup(); |
donatien | 0:0b1369ae8b74 | 118 | if(ethErr) |
donatien | 0:0b1369ae8b74 | 119 | { |
donatien | 0:0b1369ae8b74 | 120 | printf("Error %d in setup.\n", ethErr); |
donatien | 0:0b1369ae8b74 | 121 | return -1; |
donatien | 0:0b1369ae8b74 | 122 | } |
donatien | 0:0b1369ae8b74 | 123 | printf("Setup OK\n"); |
LouisReynier | 3:c2b64cce42d8 | 124 | // on définit où seront stockés les fichiers ! |
donatien | 0:0b1369ae8b74 | 125 | FSHandler::mount("/webfs", "/files"); //Mount /webfs path on /files web path |
donatien | 0:0b1369ae8b74 | 126 | FSHandler::mount("/webfs", "/"); //Mount /webfs path on web root path |
donatien | 0:0b1369ae8b74 | 127 | |
LouisReynier | 3:c2b64cce42d8 | 128 | svr.addHandler<SimpleHandler>("/hello"); // http://a.b.c.d/hello : hello world ! |
donatien | 0:0b1369ae8b74 | 129 | svr.addHandler<RPCHandler>("/rpc"); |
donatien | 0:0b1369ae8b74 | 130 | svr.addHandler<FSHandler>("/files"); |
donatien | 0:0b1369ae8b74 | 131 | svr.addHandler<FSHandler>("/"); //Default handler |
donatien | 0:0b1369ae8b74 | 132 | //Example : Access to mbed.htm : http://a.b.c.d/mbed.htm or http://a.b.c.d/files/mbed.htm |
donatien | 0:0b1369ae8b74 | 133 | |
donatien | 0:0b1369ae8b74 | 134 | svr.bind(80); |
donatien | 0:0b1369ae8b74 | 135 | |
donatien | 0:0b1369ae8b74 | 136 | printf("Listening...\n"); |
tostestas19 | 5:3754211a1b5b | 137 | |
donatien | 0:0b1369ae8b74 | 138 | Timer tm; |
donatien | 0:0b1369ae8b74 | 139 | tm.start(); |
donatien | 0:0b1369ae8b74 | 140 | //Listen indefinitely |
mbedyp | 6:2aba0ce3dedd | 141 | |
mbedyp | 6:2aba0ce3dedd | 142 | |
mbedyp | 6:2aba0ce3dedd | 143 | // Mettre la LED en VERT pour indiquer la fin de la tare |
mbedyp | 6:2aba0ce3dedd | 144 | ledB1 = 0; |
mbedyp | 6:2aba0ce3dedd | 145 | ledB2 = 1; |
mbedyp | 6:2aba0ce3dedd | 146 | |
donatien | 0:0b1369ae8b74 | 147 | while(true) |
donatien | 0:0b1369ae8b74 | 148 | { |
mbedyp | 6:2aba0ce3dedd | 149 | scale1.setScale(calibration_factor1); //Adjust to this calibration factor / Ajuster à ce facteur d'étalonnage |
mbedyp | 6:2aba0ce3dedd | 150 | scale2.setScale(calibration_factor2); //Adjust to this calibration factor / Ajuster à ce facteur d'étalonnage |
mbedyp | 6:2aba0ce3dedd | 151 | |
mbedyp | 6:2aba0ce3dedd | 152 | //------------------------------ MESURE PRINCIPAL PIERRE ------------------------------ |
mbedyp | 6:2aba0ce3dedd | 153 | if (moyenneClick == 0) { |
mbedyp | 6:2aba0ce3dedd | 154 | weight1 = scale1.getGram(); |
mbedyp | 6:2aba0ce3dedd | 155 | weight2 = scale2.getGram(); |
mbedyp | 6:2aba0ce3dedd | 156 | |
mbedyp | 6:2aba0ce3dedd | 157 | f0 = (int) weight1; |
mbedyp | 6:2aba0ce3dedd | 158 | f1 = (int) weight2; |
mbedyp | 6:2aba0ce3dedd | 159 | } |
mbedyp | 6:2aba0ce3dedd | 160 | |
mbedyp | 6:2aba0ce3dedd | 161 | m = weight1 - weight2; // Calcul masse du club |
mbedyp | 6:2aba0ce3dedd | 162 | lg = 45 * (weight1 / m); //Longueur jusqu'aux points d'équilibre |
mbedyp | 6:2aba0ce3dedd | 163 | |
mbedyp | 6:2aba0ce3dedd | 164 | MOI = m * (lg * lg); // Calcul masse du MOI (masse inertielle) |
mbedyp | 6:2aba0ce3dedd | 165 | |
mbedyp | 6:2aba0ce3dedd | 166 | calculInches = lg / convertionInches; //Convertion en inches |
mbedyp | 6:2aba0ce3dedd | 167 | SW = (calculInches - 14) * m; //Calcul SWINGWEIGHT |
mbedyp | 6:2aba0ce3dedd | 168 | //------------------------------ MESURE PRINCIPAL PIERRE ------------------------------ |
mbedyp | 6:2aba0ce3dedd | 169 | |
tostestas19 | 4:5b29715e0aaa | 170 | //F1 = 1000*Pot1.read(); |
tostestas19 | 4:5b29715e0aaa | 171 | //F2 = 1000*Pot2.read(); |
tostestas19 | 4:5b29715e0aaa | 172 | |
mbedyp | 6:2aba0ce3dedd | 173 | //pot2 = 926; |
mbedyp | 6:2aba0ce3dedd | 174 | //pot1 = 351; |
mbedyp | 6:2aba0ce3dedd | 175 | |
mbedyp | 6:2aba0ce3dedd | 176 | printf("w1 = %f g : w2 = %f g \n", weight1 , weight2); |
mbedyp | 6:2aba0ce3dedd | 177 | printf("f0 = %d g : f1 = %d g \n", f0 , f1); |
mbedyp | 6:2aba0ce3dedd | 178 | Net::poll(); |
tostestas19 | 4:5b29715e0aaa | 179 | |
tostestas19 | 4:5b29715e0aaa | 180 | |
donatien | 0:0b1369ae8b74 | 181 | if(tm.read()>.5) |
donatien | 0:0b1369ae8b74 | 182 | { |
donatien | 0:0b1369ae8b74 | 183 | led1=!led1; //Show that we are alive |
LouisReynier | 3:c2b64cce42d8 | 184 | count ++ ; |
donatien | 0:0b1369ae8b74 | 185 | tm.start(); |
donatien | 0:0b1369ae8b74 | 186 | } |
tostestas19 | 5:3754211a1b5b | 187 | |
tostestas19 | 5:3754211a1b5b | 188 | |
tostestas19 | 5:3754211a1b5b | 189 | /* |
tostestas19 | 5:3754211a1b5b | 190 | |
tostestas19 | 5:3754211a1b5b | 191 | m = f1 - f0 ; |
tostestas19 | 5:3754211a1b5b | 192 | lg = (l1*f1)/(f1-f0); |
tostestas19 | 5:3754211a1b5b | 193 | MOI = m*lg*lg/1000 ;*/ |
tostestas19 | 5:3754211a1b5b | 194 | |
mbedyp | 6:2aba0ce3dedd | 195 | switch (menu) { |
mbedyp | 6:2aba0ce3dedd | 196 | case 0: { |
mbedyp | 6:2aba0ce3dedd | 197 | //LED_BOUTON_B |
mbedyp | 6:2aba0ce3dedd | 198 | ledB1 = 0; |
mbedyp | 6:2aba0ce3dedd | 199 | ledB2 = 1; |
mbedyp | 6:2aba0ce3dedd | 200 | |
mbedyp | 6:2aba0ce3dedd | 201 | lcd.cls(); //CLEAR LCD |
mbedyp | 6:2aba0ce3dedd | 202 | lcd.locate(0, 0); //Ecrire sur la 1er ligne |
mbedyp | 6:2aba0ce3dedd | 203 | lcd.printf("F1: %.2fg\n", weight1); // Afficher le poids en grammes du capteur 1 |
mbedyp | 6:2aba0ce3dedd | 204 | |
mbedyp | 6:2aba0ce3dedd | 205 | lcd.locate(0, 1); //Ecrire sur la 2ème ligne |
mbedyp | 6:2aba0ce3dedd | 206 | lcd.printf("F0: %.2fg\n", weight2); // Afficher le poids en grammes du capteur 2 |
mbedyp | 6:2aba0ce3dedd | 207 | |
mbedyp | 6:2aba0ce3dedd | 208 | if (!Center) { |
mbedyp | 6:2aba0ce3dedd | 209 | //CODE: LED_BOUTON_A |
mbedyp | 6:2aba0ce3dedd | 210 | ledB1 = 1; |
mbedyp | 6:2aba0ce3dedd | 211 | ledB2 = 0; |
mbedyp | 6:2aba0ce3dedd | 212 | |
mbedyp | 6:2aba0ce3dedd | 213 | weight1 = 0; |
mbedyp | 6:2aba0ce3dedd | 214 | weight2 = 0; |
mbedyp | 6:2aba0ce3dedd | 215 | |
mbedyp | 6:2aba0ce3dedd | 216 | wait(1.5); // Attendre 1.5 sec |
mbedyp | 6:2aba0ce3dedd | 217 | |
mbedyp | 6:2aba0ce3dedd | 218 | while (moyenneClick == 0) { |
mbedyp | 6:2aba0ce3dedd | 219 | |
mbedyp | 6:2aba0ce3dedd | 220 | boucleExecute++; |
mbedyp | 6:2aba0ce3dedd | 221 | |
mbedyp | 6:2aba0ce3dedd | 222 | weight1 = weight1 + scale1.getGram(); |
mbedyp | 6:2aba0ce3dedd | 223 | weight2 = weight2 + scale2.getGram(); |
mbedyp | 6:2aba0ce3dedd | 224 | |
mbedyp | 6:2aba0ce3dedd | 225 | m = weight1 - weight2; // Calcul masse du club |
mbedyp | 6:2aba0ce3dedd | 226 | |
mbedyp | 6:2aba0ce3dedd | 227 | massMoy = massMoy + m; |
mbedyp | 6:2aba0ce3dedd | 228 | |
mbedyp | 6:2aba0ce3dedd | 229 | wait(0.1); // Attendre 0.1 sec |
mbedyp | 6:2aba0ce3dedd | 230 | |
mbedyp | 6:2aba0ce3dedd | 231 | massMoy = massMoy / boucleExecute; |
mbedyp | 6:2aba0ce3dedd | 232 | |
mbedyp | 6:2aba0ce3dedd | 233 | lcd.cls(); //CLEAR LCD |
mbedyp | 6:2aba0ce3dedd | 234 | lcd.locate(0, 0); //Ecrire sur la 1er ligne |
mbedyp | 6:2aba0ce3dedd | 235 | lcd.printf("Nombre de points\n"); // Afficher le nombre de points |
mbedyp | 6:2aba0ce3dedd | 236 | |
mbedyp | 6:2aba0ce3dedd | 237 | lcd.locate(0, 1); //Ecrire sur la 1er ligne |
mbedyp | 6:2aba0ce3dedd | 238 | lcd.printf("%d m: %.2fg\n", boucleExecute, massMoy); // Afficher le nombre de points |
mbedyp | 6:2aba0ce3dedd | 239 | |
mbedyp | 6:2aba0ce3dedd | 240 | //LED VERT |
mbedyp | 6:2aba0ce3dedd | 241 | ledB1 = 0; |
mbedyp | 6:2aba0ce3dedd | 242 | ledB2 = 1; |
mbedyp | 6:2aba0ce3dedd | 243 | |
mbedyp | 6:2aba0ce3dedd | 244 | //LED ROUGE |
mbedyp | 6:2aba0ce3dedd | 245 | ledB1 = 1; |
mbedyp | 6:2aba0ce3dedd | 246 | ledB2 = 0; |
mbedyp | 6:2aba0ce3dedd | 247 | |
mbedyp | 6:2aba0ce3dedd | 248 | massMoy = 0; |
mbedyp | 6:2aba0ce3dedd | 249 | |
mbedyp | 6:2aba0ce3dedd | 250 | if (!Center) { |
mbedyp | 6:2aba0ce3dedd | 251 | //LED ROUGE |
mbedyp | 6:2aba0ce3dedd | 252 | ledB1 = 0; |
mbedyp | 6:2aba0ce3dedd | 253 | ledB2 = 1; |
mbedyp | 6:2aba0ce3dedd | 254 | moyenneClick = 1; //Mettre moyenneClick a 1 |
mbedyp | 6:2aba0ce3dedd | 255 | wait(1); // Attendre 1 sec |
mbedyp | 6:2aba0ce3dedd | 256 | } |
mbedyp | 6:2aba0ce3dedd | 257 | |
mbedyp | 6:2aba0ce3dedd | 258 | } |
mbedyp | 6:2aba0ce3dedd | 259 | |
mbedyp | 6:2aba0ce3dedd | 260 | weight1 = weight1 / boucleExecute; |
mbedyp | 6:2aba0ce3dedd | 261 | weight2 = weight2 / boucleExecute; |
mbedyp | 6:2aba0ce3dedd | 262 | |
mbedyp | 6:2aba0ce3dedd | 263 | wait(0.5); // Attendre 0.5 sec |
mbedyp | 6:2aba0ce3dedd | 264 | } else if (!Down) { |
mbedyp | 6:2aba0ce3dedd | 265 | menu = 1; |
mbedyp | 6:2aba0ce3dedd | 266 | //CODE: LED_BOUTON_A |
mbedyp | 6:2aba0ce3dedd | 267 | ledB1 = 1; |
mbedyp | 6:2aba0ce3dedd | 268 | ledB2 = 0; |
mbedyp | 6:2aba0ce3dedd | 269 | |
mbedyp | 6:2aba0ce3dedd | 270 | wait(0.5); // Attendre 0.5 sec |
mbedyp | 6:2aba0ce3dedd | 271 | } else if (!Up) { |
mbedyp | 6:2aba0ce3dedd | 272 | menu = 3; |
mbedyp | 6:2aba0ce3dedd | 273 | //CODE: LED_BOUTON_A |
mbedyp | 6:2aba0ce3dedd | 274 | ledB1 = 1; |
mbedyp | 6:2aba0ce3dedd | 275 | ledB2 = 0; |
mbedyp | 6:2aba0ce3dedd | 276 | |
mbedyp | 6:2aba0ce3dedd | 277 | wait(0.5); // Attendre 0.5 sec |
mbedyp | 6:2aba0ce3dedd | 278 | } |
mbedyp | 6:2aba0ce3dedd | 279 | } |
mbedyp | 6:2aba0ce3dedd | 280 | break; |
mbedyp | 6:2aba0ce3dedd | 281 | |
mbedyp | 6:2aba0ce3dedd | 282 | case 1: { |
mbedyp | 6:2aba0ce3dedd | 283 | //LED_BOUTON_B |
mbedyp | 6:2aba0ce3dedd | 284 | ledB1 = 0; |
mbedyp | 6:2aba0ce3dedd | 285 | ledB2 = 1; |
mbedyp | 6:2aba0ce3dedd | 286 | |
mbedyp | 6:2aba0ce3dedd | 287 | lcd.cls(); //CLEAR LCD |
mbedyp | 6:2aba0ce3dedd | 288 | lcd.locate(0, 0); //Ecrire sur la 1er ligne |
mbedyp | 6:2aba0ce3dedd | 289 | lcd.printf("m = %.2fg\n", m); |
mbedyp | 6:2aba0ce3dedd | 290 | |
mbedyp | 6:2aba0ce3dedd | 291 | lg = 45 * (weight1 / m); |
mbedyp | 6:2aba0ce3dedd | 292 | lcd.locate(0, 1); //Ecrire sur la 2ème ligne |
mbedyp | 6:2aba0ce3dedd | 293 | lcd.printf("lg = %.2fcm\n", lg); |
mbedyp | 6:2aba0ce3dedd | 294 | |
mbedyp | 6:2aba0ce3dedd | 295 | if (!Down) { |
mbedyp | 6:2aba0ce3dedd | 296 | menu = 2; |
mbedyp | 6:2aba0ce3dedd | 297 | //CODE: LED_BOUTON_A |
mbedyp | 6:2aba0ce3dedd | 298 | ledB1 = 1; |
mbedyp | 6:2aba0ce3dedd | 299 | ledB2 = 0; |
mbedyp | 6:2aba0ce3dedd | 300 | wait(0.5); // Attendre 0.5 sec |
mbedyp | 6:2aba0ce3dedd | 301 | } else if (!Up) { |
mbedyp | 6:2aba0ce3dedd | 302 | menu = 0; |
mbedyp | 6:2aba0ce3dedd | 303 | //CODE: LED_BOUTON_A |
mbedyp | 6:2aba0ce3dedd | 304 | ledB1 = 1; |
mbedyp | 6:2aba0ce3dedd | 305 | ledB2 = 0; |
mbedyp | 6:2aba0ce3dedd | 306 | |
mbedyp | 6:2aba0ce3dedd | 307 | wait(0.5); // Attendre 0.5 sec |
mbedyp | 6:2aba0ce3dedd | 308 | } |
mbedyp | 6:2aba0ce3dedd | 309 | |
mbedyp | 6:2aba0ce3dedd | 310 | } |
mbedyp | 6:2aba0ce3dedd | 311 | break; |
mbedyp | 6:2aba0ce3dedd | 312 | |
mbedyp | 6:2aba0ce3dedd | 313 | case 2: { |
mbedyp | 6:2aba0ce3dedd | 314 | //LED_BOUTON_B |
mbedyp | 6:2aba0ce3dedd | 315 | ledB1 = 0; |
mbedyp | 6:2aba0ce3dedd | 316 | ledB2 = 1; |
mbedyp | 6:2aba0ce3dedd | 317 | |
mbedyp | 6:2aba0ce3dedd | 318 | lcd.cls(); //CLEAR LCD |
mbedyp | 6:2aba0ce3dedd | 319 | lcd.locate(0, 0); //Ecrire sur la 1er ligne |
mbedyp | 6:2aba0ce3dedd | 320 | lcd.printf("MOI:\n"); |
mbedyp | 6:2aba0ce3dedd | 321 | lcd.locate(0, 1); //Ecrire sur la 2ème ligne |
mbedyp | 6:2aba0ce3dedd | 322 | lcd.printf("%.2f kg.cm2\n", MOI / 1000); |
mbedyp | 6:2aba0ce3dedd | 323 | |
mbedyp | 6:2aba0ce3dedd | 324 | if (!Down) { |
mbedyp | 6:2aba0ce3dedd | 325 | menu = 3; |
mbedyp | 6:2aba0ce3dedd | 326 | //CODE: LED_BOUTON_A |
mbedyp | 6:2aba0ce3dedd | 327 | ledB1 = 1; |
mbedyp | 6:2aba0ce3dedd | 328 | ledB2 = 0; |
tostestas19 | 5:3754211a1b5b | 329 | |
mbedyp | 6:2aba0ce3dedd | 330 | wait(0.5); // Attendre 0.5 sec |
mbedyp | 6:2aba0ce3dedd | 331 | } else if (!Up) { |
mbedyp | 6:2aba0ce3dedd | 332 | menu = 1; |
mbedyp | 6:2aba0ce3dedd | 333 | //CODE: LED_BOUTON_A |
mbedyp | 6:2aba0ce3dedd | 334 | ledB1 = 1; |
mbedyp | 6:2aba0ce3dedd | 335 | ledB2 = 0; |
mbedyp | 6:2aba0ce3dedd | 336 | |
mbedyp | 6:2aba0ce3dedd | 337 | wait(0.5); // Attendre 0.5 sec |
mbedyp | 6:2aba0ce3dedd | 338 | } |
mbedyp | 6:2aba0ce3dedd | 339 | } |
mbedyp | 6:2aba0ce3dedd | 340 | break; |
mbedyp | 6:2aba0ce3dedd | 341 | |
mbedyp | 6:2aba0ce3dedd | 342 | case 3: { |
mbedyp | 6:2aba0ce3dedd | 343 | //LED_BOUTON_B |
mbedyp | 6:2aba0ce3dedd | 344 | ledB1 = 0; |
mbedyp | 6:2aba0ce3dedd | 345 | ledB2 = 1; |
mbedyp | 6:2aba0ce3dedd | 346 | |
mbedyp | 6:2aba0ce3dedd | 347 | lcd.cls(); //CLEAR LCD |
mbedyp | 6:2aba0ce3dedd | 348 | lcd.locate(0, 0); //Ecrire sur la 1er ligne |
mbedyp | 6:2aba0ce3dedd | 349 | |
mbedyp | 6:2aba0ce3dedd | 350 | lcd.printf("SW = %.2f\n", SW); |
mbedyp | 6:2aba0ce3dedd | 351 | |
mbedyp | 6:2aba0ce3dedd | 352 | lcd.locate(0, 1); //Ecrire sur la 2ème ligne |
mbedyp | 6:2aba0ce3dedd | 353 | |
mbedyp | 6:2aba0ce3dedd | 354 | // Résultat de SW (SWINGWEIGHT / inertie) place le club dans une catégorie |
mbedyp | 6:2aba0ce3dedd | 355 | if (SW < 5250) { |
mbedyp | 6:2aba0ce3dedd | 356 | lcd.printf("SWINGWEIGHT NULL\n", SW); |
mbedyp | 6:2aba0ce3dedd | 357 | } else if (SW > 5250 && SW < 5300) { |
mbedyp | 6:2aba0ce3dedd | 358 | lcd.printf("SWINGWEIGHT = B4\n"); |
mbedyp | 6:2aba0ce3dedd | 359 | } else if (SW > 5300 && SW < 5350) { |
mbedyp | 6:2aba0ce3dedd | 360 | lcd.printf("SWINGWEIGHT = B5\n"); |
mbedyp | 6:2aba0ce3dedd | 361 | } else if (SW > 5350 && SW < 5400) { |
mbedyp | 6:2aba0ce3dedd | 362 | lcd.printf("SWINGWEIGHT = B6\n"); |
mbedyp | 6:2aba0ce3dedd | 363 | } else if (SW > 5400 && SW < 5450) { |
mbedyp | 6:2aba0ce3dedd | 364 | lcd.printf("SWINGWEIGHT = B7\n"); |
mbedyp | 6:2aba0ce3dedd | 365 | } else if (SW > 5450 && SW < 5500) { |
mbedyp | 6:2aba0ce3dedd | 366 | lcd.printf("SWINGWEIGHT = B8\n"); |
mbedyp | 6:2aba0ce3dedd | 367 | } else if (SW > 5500 && SW < 5550) { |
mbedyp | 6:2aba0ce3dedd | 368 | lcd.printf("SWINGWEIGHT = B9\n"); |
mbedyp | 6:2aba0ce3dedd | 369 | } else if (SW > 5550 && SW < 5600) { |
mbedyp | 6:2aba0ce3dedd | 370 | lcd.printf("SWINGWEIGHT = C0\n"); |
mbedyp | 6:2aba0ce3dedd | 371 | } else if (SW > 5600 && SW < 5650) { |
mbedyp | 6:2aba0ce3dedd | 372 | lcd.printf("SWINGWEIGHT = C1\n"); |
mbedyp | 6:2aba0ce3dedd | 373 | } else if (SW > 5650 && SW < 5700) { |
mbedyp | 6:2aba0ce3dedd | 374 | lcd.printf("SWINGWEIGHT = C2\n"); |
mbedyp | 6:2aba0ce3dedd | 375 | } else if (SW > 5700 && SW < 5750) { |
mbedyp | 6:2aba0ce3dedd | 376 | lcd.printf("SWINGWEIGHT = C3\n"); |
mbedyp | 6:2aba0ce3dedd | 377 | } else if (SW > 5750 && SW < 5800) { |
mbedyp | 6:2aba0ce3dedd | 378 | lcd.printf("SWINGWEIGHT = C4\n"); |
mbedyp | 6:2aba0ce3dedd | 379 | } else if (SW > 5800 && SW < 5850) { |
mbedyp | 6:2aba0ce3dedd | 380 | lcd.printf("SWINGWEIGHT = C5\n"); |
mbedyp | 6:2aba0ce3dedd | 381 | } else if (SW > 5850 && SW < 5900) { |
mbedyp | 6:2aba0ce3dedd | 382 | lcd.printf("SWINGWEIGHT = C6\n"); |
mbedyp | 6:2aba0ce3dedd | 383 | } else if (SW > 5900 && SW < 5950) { |
mbedyp | 6:2aba0ce3dedd | 384 | lcd.printf("SWINGWEIGHT = C7\n"); |
mbedyp | 6:2aba0ce3dedd | 385 | } else if (SW > 5950 && SW < 6000) { |
mbedyp | 6:2aba0ce3dedd | 386 | lcd.printf("SWINGWEIGHT = C8\n"); |
mbedyp | 6:2aba0ce3dedd | 387 | } else if (SW > 6000 && SW < 6050) { |
mbedyp | 6:2aba0ce3dedd | 388 | lcd.printf("SWINGWEIGHT = C9\n"); |
mbedyp | 6:2aba0ce3dedd | 389 | } else if (SW > 6050 && SW < 6100) { |
mbedyp | 6:2aba0ce3dedd | 390 | lcd.printf("SWINGWEIGHT = D0\n"); |
mbedyp | 6:2aba0ce3dedd | 391 | } else if (SW > 6100 && SW < 6150) { |
mbedyp | 6:2aba0ce3dedd | 392 | lcd.printf("SWINGWEIGHT = D1\n"); |
mbedyp | 6:2aba0ce3dedd | 393 | } else if (SW > 6150 && SW < 6200) { |
mbedyp | 6:2aba0ce3dedd | 394 | lcd.printf("SWINGWEIGHT = D2\n"); |
mbedyp | 6:2aba0ce3dedd | 395 | } else if (SW > 6200 && SW < 6250) { |
mbedyp | 6:2aba0ce3dedd | 396 | lcd.printf("SWINGWEIGHT = D3\n"); |
mbedyp | 6:2aba0ce3dedd | 397 | } else if (SW > 6250 && SW < 6300) { |
mbedyp | 6:2aba0ce3dedd | 398 | lcd.printf("SWINGWEIGHT = D4\n"); |
mbedyp | 6:2aba0ce3dedd | 399 | } else if (SW > 6300 && SW < 6350) { |
mbedyp | 6:2aba0ce3dedd | 400 | lcd.printf("SWINGWEIGHT = D5\n"); |
mbedyp | 6:2aba0ce3dedd | 401 | } else if (SW > 6350 && SW < 6400) { |
mbedyp | 6:2aba0ce3dedd | 402 | lcd.printf("SWINGWEIGHT = D6\n"); |
mbedyp | 6:2aba0ce3dedd | 403 | } else if (SW > 6400 && SW < 6450) { |
mbedyp | 6:2aba0ce3dedd | 404 | lcd.printf("SWINGWEIGHT = D7\n"); |
mbedyp | 6:2aba0ce3dedd | 405 | } else if (SW > 6450 && SW < 6500) { |
mbedyp | 6:2aba0ce3dedd | 406 | lcd.printf("SWINGWEIGHT = D8\n"); |
mbedyp | 6:2aba0ce3dedd | 407 | } else if (SW > 6500) { |
mbedyp | 6:2aba0ce3dedd | 408 | lcd.printf("SWINGWEIGHT = D9\n"); |
mbedyp | 6:2aba0ce3dedd | 409 | } |
mbedyp | 6:2aba0ce3dedd | 410 | |
mbedyp | 6:2aba0ce3dedd | 411 | if (!Down) { |
mbedyp | 6:2aba0ce3dedd | 412 | menu = 4; |
mbedyp | 6:2aba0ce3dedd | 413 | //CODE: LED_BOUTON_A |
mbedyp | 6:2aba0ce3dedd | 414 | ledB1 = 1; |
mbedyp | 6:2aba0ce3dedd | 415 | ledB2 = 0; |
mbedyp | 6:2aba0ce3dedd | 416 | |
mbedyp | 6:2aba0ce3dedd | 417 | wait(0.5); // Attendre 0.5 sec |
mbedyp | 6:2aba0ce3dedd | 418 | } else if (!Up) { |
mbedyp | 6:2aba0ce3dedd | 419 | menu = 2; |
mbedyp | 6:2aba0ce3dedd | 420 | //CODE: LED_BOUTON_A |
mbedyp | 6:2aba0ce3dedd | 421 | ledB1 = 1; |
mbedyp | 6:2aba0ce3dedd | 422 | ledB2 = 0; |
mbedyp | 6:2aba0ce3dedd | 423 | |
mbedyp | 6:2aba0ce3dedd | 424 | wait(0.5); // Attendre 0.5 sec |
mbedyp | 6:2aba0ce3dedd | 425 | } |
mbedyp | 6:2aba0ce3dedd | 426 | } |
mbedyp | 6:2aba0ce3dedd | 427 | break; |
mbedyp | 6:2aba0ce3dedd | 428 | |
mbedyp | 6:2aba0ce3dedd | 429 | case 4: { |
mbedyp | 6:2aba0ce3dedd | 430 | //LED_BOUTON_B |
mbedyp | 6:2aba0ce3dedd | 431 | ledB1 = 0; |
mbedyp | 6:2aba0ce3dedd | 432 | ledB2 = 1; |
mbedyp | 6:2aba0ce3dedd | 433 | |
mbedyp | 6:2aba0ce3dedd | 434 | lcd.cls(); //CLEAR LCD |
mbedyp | 6:2aba0ce3dedd | 435 | lcd.locate(0, 0); //Ecrire sur la 1er ligne |
mbedyp | 6:2aba0ce3dedd | 436 | |
mbedyp | 6:2aba0ce3dedd | 437 | lcd.printf("N points moyenne"); |
mbedyp | 6:2aba0ce3dedd | 438 | |
mbedyp | 6:2aba0ce3dedd | 439 | lcd.locate(0, 1); //Ecrire sur la 2eme ligne |
mbedyp | 6:2aba0ce3dedd | 440 | lcd.printf("%d\n", boucleExecute); |
mbedyp | 6:2aba0ce3dedd | 441 | |
mbedyp | 6:2aba0ce3dedd | 442 | if (!Down) { |
mbedyp | 6:2aba0ce3dedd | 443 | menu = 0; |
mbedyp | 6:2aba0ce3dedd | 444 | //CODE: LED_BOUTON_A |
mbedyp | 6:2aba0ce3dedd | 445 | ledB1 = 1; |
mbedyp | 6:2aba0ce3dedd | 446 | ledB2 = 0; |
mbedyp | 6:2aba0ce3dedd | 447 | |
mbedyp | 6:2aba0ce3dedd | 448 | wait(0.5); // Attendre 0.5 sec |
mbedyp | 6:2aba0ce3dedd | 449 | } else if (!Up) { |
mbedyp | 6:2aba0ce3dedd | 450 | menu = 3; |
mbedyp | 6:2aba0ce3dedd | 451 | //CODE: LED_BOUTON_A |
mbedyp | 6:2aba0ce3dedd | 452 | ledB1 = 1; |
mbedyp | 6:2aba0ce3dedd | 453 | ledB2 = 0; |
mbedyp | 6:2aba0ce3dedd | 454 | |
mbedyp | 6:2aba0ce3dedd | 455 | wait(0.5); // Attendre 0.5 sec |
mbedyp | 6:2aba0ce3dedd | 456 | } |
mbedyp | 6:2aba0ce3dedd | 457 | } |
mbedyp | 6:2aba0ce3dedd | 458 | break; |
tostestas19 | 5:3754211a1b5b | 459 | // http://192.168.1.102/rpc/pot1/read dans le navigateur permet de lire l'état du potard ! |
mbedyp | 6:2aba0ce3dedd | 460 | } //FIN SWITCH |
donatien | 0:0b1369ae8b74 | 461 | |
mbedyp | 6:2aba0ce3dedd | 462 | } //FIN WHILE |
mbedyp | 6:2aba0ce3dedd | 463 | } //FIN MAIN |