Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed HTTPServer EthernetNetIf HX711 TextLCD RPCInterface
Revision 6:2aba0ce3dedd, committed 2022-06-11
- Comitter:
- mbedyp
- Date:
- Sat Jun 11 22:21:00 2022 +0000
- Parent:
- 5:3754211a1b5b
- Commit message:
- float impossible dans RPC donc weight1 et 2 en float > f0 et f1 en int; pour sa: f0 = (int) weight1;....
Changed in this revision
| HTTPServerExample.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 3754211a1b5b -r 2aba0ce3dedd HTTPServerExample.cpp
--- a/HTTPServerExample.cpp Sat Jun 11 21:11:21 2022 +0000
+++ b/HTTPServerExample.cpp Sat Jun 11 22:21:00 2022 +0000
@@ -15,21 +15,21 @@
// LCD and Joystick Setting
TextLCD lcd(p8, p10, p11, p5, p6, p7); // rs, e, d4-d7
//rs e d4 d5 d6 d7
+DigitalOut RW(p9);
+//LED MBED
DigitalOut led1(LED1);
DigitalOut led2(LED2);
DigitalOut led3(LED3);
DigitalOut led4(LED4);
-DigitalOut RW(p9);
+//LED BICOLORE
+DigitalOut ledB1(p29); // SI 1 LED ROUGE
+DigitalOut ledB2(p30); // SI 1 LED VERT
+
//AnalogIn Pot1(p19, "pot1");
//AnalogIn Pot2(p20, "pot2");
-//LED BICOLORE
-//DigitalOut ledB1(p29); // SI 1 LED ROUGE
-//DigitalOut ledB2(p30); // SI 1 LED VERT
-DigitalOut myledR(p30); // LED Rouge
-DigitalOut myledV(p29); // LED Vert
// BOUTON
DigitalIn Up(p12);
@@ -50,21 +50,31 @@
//int pot1 ; a renplacer
//int pot2; a remplacer
-int MOI = 0; // en kg*cm2
-int f0 = 256 ; //256 ; // en g
-int f1 = 657 ; //657 ; // en g
-int m = 0 ; // en g
-int l1 = 45 ; // en cm
-int lg = 0 ; // en cm
-int menu = 0;
-int tempo_saisie = 130 ;
-
float calibration_factor1 = 2325; //2325 // -7050 worked for my 440lb max scale setup
float calibration_factor2 = 2178; //2178
int averageSamples = 5; //NOMBRE DE MESURE
-float weight1 = 0; // F1
-float weight2 = 0; // F0
+
+int moyenneClick = 0;
+int boucleExecute = 0;
+
+int menu = 0;
+
+float m = 0; //MASSE en g
+float lg = 0; //LG en cm
+float MOI = 0; // MOI en kg*cm2
+float massMoy = 0; //Moyenne de la masse a chaque points
+
+float weight1 = 0; // F0
+float weight2 = 0; // F1
+
+int f0 = 0;
+int f1 = 0;
+
+//SWINGWEIGHT
+float convertionInches = 2.54; // 1 inches = 2,54 centimètre
+float calculInches = 0; // Variable pour effectuer des calculs
+float SW = 0; // Variable résultat SWINGWEIGHT
RPCVariable<int> rpc_f0(&f0, "f0");
RPCVariable<int> rpc_f1(&f1, "f1");
@@ -76,24 +86,22 @@
EthernetNetIf eth;
HTTPServer svr;
-
-
+int main() {
-int main() {
+ //Mettre la LED bicolore en ROUGE pendant la tare
+ ledB1 = 1;
+ ledB2 = 0;
+ RW = 0;
- menu = 0 ;
- RW = 0 ;
-
-
-
-
- lcd.locate(0,0);
- lcd.printf(" mesure MOI ");
- lcd.locate(0,1);
- lcd.printf(" club de golf ");
- wait_ms(2000);
- lcd.cls();
-
+ scale1.setScale(0);
+ scale1.tare(); //Reset the scale to 0
+
+ scale2.setScale(0);
+ scale2.tare(); //Reset the scale to 0
+
+ long zero_factor1 = scale1.averageValue(averageSamples); //Get a baseline reading / Obtenez une lecture de base CAPTEUR 1
+ long zero_factor2 = scale2.averageValue(averageSamples); //Get a baseline reading / Obtenez une lecture de base CAPTEUR 2
+
Base::add_rpc_class<DigitalOut>();
printf("Setting up...\n");
@@ -126,41 +134,48 @@
svr.bind(80);
printf("Listening...\n");
- scale1.setScale(0);
- scale1.tare(); //Reset the scale to 0
- scale2.setScale(0);
- scale2.tare(); //Reset the scale to 0
- long zero_factor1 = scale1.averageValue(averageSamples); //Get a baseline reading / Obtenez une lecture de base CAPTEUR 1
- long zero_factor2 = scale2.averageValue(averageSamples); //Get a baseline reading / Obtenez une lecture de base CAPTEUR 2
- scale1.setScale(calibration_factor1); //Adjust to this calibration factor / Ajuster à ce facteur d'étalonnage
- scale2.setScale(calibration_factor2); //Adjust to this calibration factor / Ajuster à ce facteur d'étalonnage
-
-
Timer tm;
tm.start();
//Listen indefinitely
-
+
+
+ // Mettre la LED en VERT pour indiquer la fin de la tare
+ ledB1 = 0;
+ ledB2 = 1;
+
while(true)
{
+ scale1.setScale(calibration_factor1); //Adjust to this calibration factor / Ajuster à ce facteur d'étalonnage
+ scale2.setScale(calibration_factor2); //Adjust to this calibration factor / Ajuster à ce facteur d'étalonnage
+
+ //------------------------------ MESURE PRINCIPAL PIERRE ------------------------------
+ if (moyenneClick == 0) {
+ weight1 = scale1.getGram();
+ weight2 = scale2.getGram();
+
+ f0 = (int) weight1;
+ f1 = (int) weight2;
+ }
+
+ m = weight1 - weight2; // Calcul masse du club
+ lg = 45 * (weight1 / m); //Longueur jusqu'aux points d'équilibre
+
+ MOI = m * (lg * lg); // Calcul masse du MOI (masse inertielle)
+
+ calculInches = lg / convertionInches; //Convertion en inches
+ SW = (calculInches - 14) * m; //Calcul SWINGWEIGHT
+ //------------------------------ MESURE PRINCIPAL PIERRE ------------------------------
+
//F1 = 1000*Pot1.read();
//F2 = 1000*Pot2.read();
- // pot2 = 926;
- //pot1 = 351;
- wait_ms(100);
- weight1 = scale1.getGram();
-
- weight2 = scale2.getGram();
-
- // f0 = (int) weight1 ;
- // f1 = (int) weight2 ;
-
- f0 = weight1 ;
- f1 = weight2 ;
- printf("wo = %f g : w1 = %f g \n", weight1 , weight2);
- printf("fo = %d g : fi = %d g \n", f0 , f1);
- Net::poll();
+ //pot2 = 926;
+ //pot1 = 351;
+
+ printf("w1 = %f g : w2 = %f g \n", weight1 , weight2);
+ printf("f0 = %d g : f1 = %d g \n", f0 , f1);
+ Net::poll();
if(tm.read()>.5)
@@ -177,212 +192,272 @@
lg = (l1*f1)/(f1-f0);
MOI = m*lg*lg/1000 ;*/
- switch(menu)
-{
-
- case(0):
-
- lcd.locate(1,0);
- lcd.printf("*Mesures Forces");
- lcd.locate(1,1);
- lcd.printf(" Calcul MOI ");
- wait_ms(tempo_saisie);
-
- if (!Center ){
- lcd.cls();
- menu = 3 ;
- }
-
- if (!Down){
- lcd.cls();
- menu = 1 ;}
-
- if (!Right ){
- lcd.cls();
- menu = 7 ;
- }
-
- myledV = 0;
- myledR = 0;
-
-
- break; //fin case 0
-
-
- case(1):
-
-
-
- lcd.locate(1,0);
- lcd.printf(" Mesures Forces");
- lcd.locate(1,1);
- lcd.printf("*Calcul MOI ");
- wait_ms(tempo_saisie);
-
- if (!Center ){
- lcd.cls();
- menu = 4 ;
- }
-
- if (!Down){
- lcd.cls();
- menu = 2 ;}
-
- if (!Up){
- lcd.cls();
- menu = 0 ;}
-
- if (!Right ){
- lcd.cls();
- menu = 7 ;
- }
- myledV = 0;
- myledR = 0;
-
-
- break; //fin case 1
-
-
- case (2):
-
- lcd.locate(1,0);
- lcd.printf(" Calcul MOI ");
- lcd.locate(1,1);
- lcd.printf("*Masse/longueur");
- wait_ms(tempo_saisie);
-
- if (!Center ){
- lcd.cls();
- menu = 5 ;
- }
-
- if (!Up){
- lcd.cls();
- menu = 1 ;}
-
- if (!Right ){
- lcd.cls();
- menu = 7 ;
- }
-
-
- myledV = 0;
- myledR = 0;
-
- break; //fin case 2
-
- case (3):
-
- lcd.locate(1,0);
- lcd.printf("F0 = %d g", f0);
- lcd.locate(1,1);
- lcd.printf("F1 = %d g", f1);
- wait_ms(tempo_saisie);
-
- if (!Left ){
- lcd.cls();
- menu = 0 ;
- }
-
- myledV = 1;
- wait(0.2);
- myledV = 0;
- wait(0.2);
- myledR = 0;
-
+switch (menu) {
+ case 0: {
+ //LED_BOUTON_B
+ ledB1 = 0;
+ ledB2 = 1;
+
+ lcd.cls(); //CLEAR LCD
+ lcd.locate(0, 0); //Ecrire sur la 1er ligne
+ lcd.printf("F1: %.2fg\n", weight1); // Afficher le poids en grammes du capteur 1
+
+ lcd.locate(0, 1); //Ecrire sur la 2ème ligne
+ lcd.printf("F0: %.2fg\n", weight2); // Afficher le poids en grammes du capteur 2
+
+ if (!Center) {
+ //CODE: LED_BOUTON_A
+ ledB1 = 1;
+ ledB2 = 0;
+
+ weight1 = 0;
+ weight2 = 0;
+
+ wait(1.5); // Attendre 1.5 sec
+
+ while (moyenneClick == 0) {
+
+ boucleExecute++;
+
+ weight1 = weight1 + scale1.getGram();
+ weight2 = weight2 + scale2.getGram();
+
+ m = weight1 - weight2; // Calcul masse du club
+
+ massMoy = massMoy + m;
+
+ wait(0.1); // Attendre 0.1 sec
+
+ massMoy = massMoy / boucleExecute;
+
+ lcd.cls(); //CLEAR LCD
+ lcd.locate(0, 0); //Ecrire sur la 1er ligne
+ lcd.printf("Nombre de points\n"); // Afficher le nombre de points
+
+ lcd.locate(0, 1); //Ecrire sur la 1er ligne
+ lcd.printf("%d m: %.2fg\n", boucleExecute, massMoy); // Afficher le nombre de points
+
+ //LED VERT
+ ledB1 = 0;
+ ledB2 = 1;
+
+ //LED ROUGE
+ ledB1 = 1;
+ ledB2 = 0;
+
+ massMoy = 0;
+
+ if (!Center) {
+ //LED ROUGE
+ ledB1 = 0;
+ ledB2 = 1;
+ moyenneClick = 1; //Mettre moyenneClick a 1
+ wait(1); // Attendre 1 sec
+ }
+
+ }
+
+ weight1 = weight1 / boucleExecute;
+ weight2 = weight2 / boucleExecute;
+
+ wait(0.5); // Attendre 0.5 sec
+ } else if (!Down) {
+ menu = 1;
+ //CODE: LED_BOUTON_A
+ ledB1 = 1;
+ ledB2 = 0;
+
+ wait(0.5); // Attendre 0.5 sec
+ } else if (!Up) {
+ menu = 3;
+ //CODE: LED_BOUTON_A
+ ledB1 = 1;
+ ledB2 = 0;
+
+ wait(0.5); // Attendre 0.5 sec
+ }
+ }
+ break;
+
+ case 1: {
+ //LED_BOUTON_B
+ ledB1 = 0;
+ ledB2 = 1;
+
+ lcd.cls(); //CLEAR LCD
+ lcd.locate(0, 0); //Ecrire sur la 1er ligne
+ lcd.printf("m = %.2fg\n", m);
+
+ lg = 45 * (weight1 / m);
+ lcd.locate(0, 1); //Ecrire sur la 2ème ligne
+ lcd.printf("lg = %.2fcm\n", lg);
+
+ if (!Down) {
+ menu = 2;
+ //CODE: LED_BOUTON_A
+ ledB1 = 1;
+ ledB2 = 0;
+ wait(0.5); // Attendre 0.5 sec
+ } else if (!Up) {
+ menu = 0;
+ //CODE: LED_BOUTON_A
+ ledB1 = 1;
+ ledB2 = 0;
+
+ wait(0.5); // Attendre 0.5 sec
+ }
+
+ }
+ break;
+
+ case 2: {
+ //LED_BOUTON_B
+ ledB1 = 0;
+ ledB2 = 1;
+
+ lcd.cls(); //CLEAR LCD
+ lcd.locate(0, 0); //Ecrire sur la 1er ligne
+ lcd.printf("MOI:\n");
+ lcd.locate(0, 1); //Ecrire sur la 2ème ligne
+ lcd.printf("%.2f kg.cm2\n", MOI / 1000);
+
+ if (!Down) {
+ menu = 3;
+ //CODE: LED_BOUTON_A
+ ledB1 = 1;
+ ledB2 = 0;
- break; //fin case 3
-
- case (4):
-
- lcd.locate(0,0);
- lcd.printf("MOI= %d kg*cm2", MOI);
- wait_ms(tempo_saisie);
-
- if (!Left ){
- lcd.cls();
- menu = 1 ;
- }
-
- myledR = 1;
- wait(0.2);
- myledR = 0;
- wait(0.2);
- myledV = 0;
-
-
- break; //fin case 4
-
- case (5):
-
- lcd.locate(1,0);
- lcd.printf(" Masse = %d g" , m);
- wait_ms(tempo_saisie);
-
- if (!Left ){
- lcd.cls();
- menu = 2 ;
- }
-
- if (!Right ){
- lcd.cls();
- menu = 6 ;
- }
-
-
- myledV = 1;
- myledR = 0;
-
-
- break; //fin case 5
-
-
- case (6):
-
- lcd.locate(1,0);
- lcd.printf(" l1 = %d cm" , l1);
- lcd.locate(1,1);
- lcd.printf(" lg = %d cm" , lg);
- wait_ms(tempo_saisie);
-
- if (!Left ){
- lcd.cls();
- menu = 2 ;
- }
-
- myledR = 1;
- myledV = 0;
-
-
- break; //fin case 6
-
-
- case (7):
-
-
- lcd.locate(1,0);
- lcd.printf(" HTML ");
- wait_ms(tempo_saisie);
-
- if (!Left ){
- lcd.cls();
- menu = 0 ;
- }
-
- myledR = 1;
- wait(0.2);
- myledV = 0;
- wait(0.2);
-
- myledR = 0;
- wait(0.2);
- myledV = 1;
- wait(0.2);
-
- break; //fin case 7
+ wait(0.5); // Attendre 0.5 sec
+ } else if (!Up) {
+ menu = 1;
+ //CODE: LED_BOUTON_A
+ ledB1 = 1;
+ ledB2 = 0;
+
+ wait(0.5); // Attendre 0.5 sec
+ }
+ }
+ break;
+
+ case 3: {
+ //LED_BOUTON_B
+ ledB1 = 0;
+ ledB2 = 1;
+
+ lcd.cls(); //CLEAR LCD
+ lcd.locate(0, 0); //Ecrire sur la 1er ligne
+
+ lcd.printf("SW = %.2f\n", SW);
+
+ lcd.locate(0, 1); //Ecrire sur la 2ème ligne
+
+ // Résultat de SW (SWINGWEIGHT / inertie) place le club dans une catégorie
+ if (SW < 5250) {
+ lcd.printf("SWINGWEIGHT NULL\n", SW);
+ } else if (SW > 5250 && SW < 5300) {
+ lcd.printf("SWINGWEIGHT = B4\n");
+ } else if (SW > 5300 && SW < 5350) {
+ lcd.printf("SWINGWEIGHT = B5\n");
+ } else if (SW > 5350 && SW < 5400) {
+ lcd.printf("SWINGWEIGHT = B6\n");
+ } else if (SW > 5400 && SW < 5450) {
+ lcd.printf("SWINGWEIGHT = B7\n");
+ } else if (SW > 5450 && SW < 5500) {
+ lcd.printf("SWINGWEIGHT = B8\n");
+ } else if (SW > 5500 && SW < 5550) {
+ lcd.printf("SWINGWEIGHT = B9\n");
+ } else if (SW > 5550 && SW < 5600) {
+ lcd.printf("SWINGWEIGHT = C0\n");
+ } else if (SW > 5600 && SW < 5650) {
+ lcd.printf("SWINGWEIGHT = C1\n");
+ } else if (SW > 5650 && SW < 5700) {
+ lcd.printf("SWINGWEIGHT = C2\n");
+ } else if (SW > 5700 && SW < 5750) {
+ lcd.printf("SWINGWEIGHT = C3\n");
+ } else if (SW > 5750 && SW < 5800) {
+ lcd.printf("SWINGWEIGHT = C4\n");
+ } else if (SW > 5800 && SW < 5850) {
+ lcd.printf("SWINGWEIGHT = C5\n");
+ } else if (SW > 5850 && SW < 5900) {
+ lcd.printf("SWINGWEIGHT = C6\n");
+ } else if (SW > 5900 && SW < 5950) {
+ lcd.printf("SWINGWEIGHT = C7\n");
+ } else if (SW > 5950 && SW < 6000) {
+ lcd.printf("SWINGWEIGHT = C8\n");
+ } else if (SW > 6000 && SW < 6050) {
+ lcd.printf("SWINGWEIGHT = C9\n");
+ } else if (SW > 6050 && SW < 6100) {
+ lcd.printf("SWINGWEIGHT = D0\n");
+ } else if (SW > 6100 && SW < 6150) {
+ lcd.printf("SWINGWEIGHT = D1\n");
+ } else if (SW > 6150 && SW < 6200) {
+ lcd.printf("SWINGWEIGHT = D2\n");
+ } else if (SW > 6200 && SW < 6250) {
+ lcd.printf("SWINGWEIGHT = D3\n");
+ } else if (SW > 6250 && SW < 6300) {
+ lcd.printf("SWINGWEIGHT = D4\n");
+ } else if (SW > 6300 && SW < 6350) {
+ lcd.printf("SWINGWEIGHT = D5\n");
+ } else if (SW > 6350 && SW < 6400) {
+ lcd.printf("SWINGWEIGHT = D6\n");
+ } else if (SW > 6400 && SW < 6450) {
+ lcd.printf("SWINGWEIGHT = D7\n");
+ } else if (SW > 6450 && SW < 6500) {
+ lcd.printf("SWINGWEIGHT = D8\n");
+ } else if (SW > 6500) {
+ lcd.printf("SWINGWEIGHT = D9\n");
+ }
+
+ if (!Down) {
+ menu = 4;
+ //CODE: LED_BOUTON_A
+ ledB1 = 1;
+ ledB2 = 0;
+
+ wait(0.5); // Attendre 0.5 sec
+ } else if (!Up) {
+ menu = 2;
+ //CODE: LED_BOUTON_A
+ ledB1 = 1;
+ ledB2 = 0;
+
+ wait(0.5); // Attendre 0.5 sec
+ }
+ }
+ break;
+
+ case 4: {
+ //LED_BOUTON_B
+ ledB1 = 0;
+ ledB2 = 1;
+
+ lcd.cls(); //CLEAR LCD
+ lcd.locate(0, 0); //Ecrire sur la 1er ligne
+
+ lcd.printf("N points moyenne");
+
+ lcd.locate(0, 1); //Ecrire sur la 2eme ligne
+ lcd.printf("%d\n", boucleExecute);
+
+ if (!Down) {
+ menu = 0;
+ //CODE: LED_BOUTON_A
+ ledB1 = 1;
+ ledB2 = 0;
+
+ wait(0.5); // Attendre 0.5 sec
+ } else if (!Up) {
+ menu = 3;
+ //CODE: LED_BOUTON_A
+ ledB1 = 1;
+ ledB2 = 0;
+
+ wait(0.5); // Attendre 0.5 sec
+ }
+ }
+ break;
// http://192.168.1.102/rpc/pot1/read dans le navigateur permet de lire l'état du potard !
- }
+ } //FIN SWITCH
-
-}
-}
\ No newline at end of file
+} //FIN WHILE
+} //FIN MAIN
\ No newline at end of file