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 HX711 TextLCD
Revision 2:f99a06ab3acc, committed 2022-05-31
- Comitter:
- abdoudasilveira
- Date:
- Tue May 31 12:18:30 2022 +0000
- Parent:
- 1:f6e3e0f785cd
- Commit message:
- projet BTS
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Tue May 31 07:11:11 2022 +0000
+++ b/main.cpp Tue May 31 12:18:30 2022 +0000
@@ -2,13 +2,15 @@
#include "HX711.h"
#include "TextLCD.h"
+#define BLINKING_RATE 0.5
+#define temps_on 0.5
+
// LCD and Joystick Setting
TextLCD lcd(p8, p10, p11, p5, p6, p7); // rs, e, d4-d7
-//rs e d4 d5 d6 d7
+ //rs e d4 d5 d6 d7
+
DigitalOut RW(p9);
-DigitalOut gpo(D0);
-
//LED MBED
DigitalOut led1(LED1);
DigitalOut led2(LED2);
@@ -16,8 +18,10 @@
DigitalOut led4(LED4);
//LED BICOLORE
-DigitalOut ledB1(p29); // SI 1 LED ROUGE
-DigitalOut ledB2(p30); // SI 1 LED VERT
+//DigitalOut ledB1(p29); // SI 1 LED ROUGE
+//DigitalOut ledB2(p30); // SI 1 LED VERT
+DigitalOut myledR(p30); // LED Rouge
+DigitalOut myledV(p29); // LED Vert
//HX711
HX711 scale1(p22, p21); //22 , 21
@@ -30,367 +34,262 @@
DigitalIn Right(p15);
DigitalIn Center(p16);
-AnalogIn scaleRaw(A3);
-Serial pc(USBTX, USBRX); // USB Serial Terminal
+int MOI = 0; // en kg*cm2
+int f0 = 256 ; // en g
+int f1 = 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
-
-int moyenneClick = 0;
-int boucleExecute = 0;
-
-int i = 0; //count
-int ii = 0; //count
-
-float m = 0; //MASSE
-float lg = 0; //LG
-float MOI = 0; // MOI
-float massMoy = 0; //Moyenne de la masse a chaque points
-
float weight1 = 0; // F1
float weight2 = 0; // F0
-//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
int main(void) {
- //Mettre la LED bicolore en ROUGE pendant la tare
- ledB1 = 1;
- ledB2 = 0;
- RW = 0;
+
+
+ RW = 0;
+ menu = 0 ;
- pc.printf("Starting Scale\n");
- pc.printf("HX711 calibration sketch\n");
- pc.printf("Retirer tout les poids des capteurs\n");
- pc.printf("Une fois que la LED bicolore passe de rouge a verte placer le club\n");
- pc.printf("[capteur1] Press 1 or a pour augmenter le facteur etalonnage de 25\n");
- pc.printf("[capteur1] Press 3 or z pour diminuer le facteur etalonnage de 25\n");
- pc.printf("[capteur2] Press 4 or a pour augmenter le facteur etalonnage de 25\n");
- pc.printf("[capteur2] Press 6 or z pour diminuer le facteur etalonnage de 25\n");
-
- scale1.setScale(0);
- scale1.tare(); //Reset the scale to 0
+ 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
- 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
- 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
-
- // 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
-
- if (moyenneClick == 0) {
+ scale2.setScale(0);
+ scale2.tare(); //Reset the scale to 0
+
+ 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
+
+
+ lcd.locate(0,0);
+ lcd.printf(" mesure MOI ");
+ lcd.locate(0,1);
+ lcd.printf(" club de golf ");
+ wait_ms(2000);
+ lcd.cls();
+
+
+ while(1)
+ {
weight1 = scale1.getGram();
weight2 = scale2.getGram();
- }
-
- //float raw = scaleRaw.read();
- pc.printf("Reading Capteur1 g : %.2f\n", weight1);
- //pc.printf("Raw Value: %.7f\n", raw);
- pc.printf("Reading Capteur2 g : %.2f\n", 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
-
- switch (i) {
- 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) {
- i = 1;
- //CODE: LED_BOUTON_A
- ledB1 = 1;
- ledB2 = 0;
-
- wait(0.5); // Attendre 0.5 sec
- } else if (!Up) {
- i = 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) {
- i = 2;
- //CODE: LED_BOUTON_A
- ledB1 = 1;
- ledB2 = 0;
- wait(0.5); // Attendre 0.5 sec
- } else if (!Up) {
- i = 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) {
- i = 3;
- //CODE: LED_BOUTON_A
- ledB1 = 1;
- ledB2 = 0;
+
+ f0 = (int) weight1 ;
+ f1 = (int) weight2 ;
+
+
+ m = f1 - f0 ;
+ 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;
+
- wait(0.5); // Attendre 0.5 sec
- } else if (!Up) {
- i = 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) {
- i = 4;
- //CODE: LED_BOUTON_A
- ledB1 = 1;
- ledB2 = 0;
-
- wait(0.5); // Attendre 0.5 sec
- } else if (!Up) {
- i = 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) {
- i = 0;
- //CODE: LED_BOUTON_A
- ledB1 = 1;
- ledB2 = 0;
-
- wait(0.5); // Attendre 0.5 sec
- } else if (!Up) {
- i = 3;
- //CODE: LED_BOUTON_A
- ledB1 = 1;
- ledB2 = 0;
-
- wait(0.5); // Attendre 0.5 sec
- }
- }
- break;
- }
- /*
- CODE INFORMATION:
- LED_BOUTON_A: Mettre la LED bicolore en ROUGE pour que l'utilisateur sache que son action a était pris en compte
- LED_BOUTON_B: Mettre la LED bicolore en VERT à la fin de l'action utilisateur
+ 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
+
- */
-
- if (pc.readable()) {
- char temp = pc.getc();
- if (temp == '1' || temp == 'a')
- calibration_factor1 -= 25;
- else if (temp == '3' || temp == 'z')
- calibration_factor1 += 25;
- else if (temp == '4' || temp == 'q')
- calibration_factor2 -= 25;
- else if (temp == '6' || temp == 's')
- calibration_factor2 += 25;
- }
- gpo = !gpo; // toggle pin
- wait(0.2); // Attendre 0.2 sec
- }
-}
\ No newline at end of file
+ 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
+
+ } } }
\ No newline at end of file