Weight-machine-App

Dependencies:   HX711 ST7567 mbed

Files at this revision

API Documentation at this revision

Comitter:
josespaul
Date:
Fri Jan 20 11:49:14 2017 +0000
Parent:
0:bca8659e032c
Commit message:
optimised code. lcd support added

Changed in this revision

ST7567.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r bca8659e032c -r c72a74304949 ST7567.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ST7567.lib	Fri Jan 20 11:49:14 2017 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/MACRUM/code/ST7567/#743aff4786ba
diff -r bca8659e032c -r c72a74304949 main.cpp
--- a/main.cpp	Mon Jan 16 17:13:23 2017 +0000
+++ b/main.cpp	Fri Jan 20 11:49:14 2017 +0000
@@ -1,40 +1,47 @@
 #include "mbed.h"
 #include "HX711.h"
-
-#define STEPS 64.0
+#include "ST7567.h"
+#define STEPS 100.0
 #define MAX_WEIGHT 2.0
 
-Serial pc(USBTX,USBRX,115200);         // Déclaration du port série USB
-HX711 Balance(P3_25,P3_26);     // Déclaration de l'objet HX711
+ST7567 lcd(P1_24, P1_20, P1_25, P1_22, P1_21); // mosi, sclk, reset, A0, nCS
+Serial pc(USBTX,USBRX,115200);         
+HX711 Balance(P3_25,P3_26);     
 PwmOut ser_mtr(P2_3);
 
 int main()
 {
-     
-     long valeur;
-     long valeurTare;
+     float current_value;
+     float initial_value;
      float weight;
-     float i;
-     float j;
-     valeurTare = Balance.getValue();
-     pc.printf("Calibtrating Sesnsors ..");
-     ser_mtr.write(0.05);
+     float i,j;
+     lcd.set_contrast(0x3F);
+     lcd.cls();
+     lcd.locate(0, 1);
+     lcd.printf("\n\n\n          Hello !");
+     wait(2);
+     lcd.cls();
+     lcd.locate(0, 1);
+     lcd.printf("\n\n\n    Calibtrating Sensors ..");
+     ser_mtr.write(0.05f);
      wait(1);
-     ser_mtr.write(0.15f);
+     initial_value = Balance.getValue();
+     ser_mtr.write(0.105f);
      wait(1);
+     lcd.cls();
+     
      while (true)
      {
-        valeur = Balance.getValue();                                          
-        weight = ((float)valeur-(float)valeurTare)/315701;         
-        pc.printf("Valeur : %ld   Kilograms :%.3lf\n",valeur,weight);
-        
-        for(i=0, j=0.10; i<=MAX_WEIGHT, j>=0.05; i=i+(MAX_WEIGHT/STEPS), j=j-(0.05/STEPS)) {
-             if(weight <= 0.10)
-             ser_mtr.write(0.15);
-             else if(weight >= i)
+        current_value = Balance.getValue();                                          
+        weight = ((float)current_value-(float)initial_value)/315701; //Calibration - 315701 is the corresponding value for 1KG
+        lcd.locate(4, 4);
+        if (weight < 0.005)
+        weight = 0.00;         
+        lcd.printf("\n\n\n     Weight %.3lf KG",weight);
+        //pc.printf("current_value : %ld   Kilograms :%.3lf\n",current_value,weight);
+        for(i=0, j=0.105; i<=MAX_WEIGHT; i=i+(MAX_WEIGHT/STEPS), j=j-(0.055/STEPS)) {
+                if(weight >= i)
              ser_mtr.write(j);
             }  
-        wait(0.700);
-     }
-     
+     } 
 }
\ No newline at end of file