Obtiene datos de una bascula y pinta el valor del int devuelto en un LCD por i2c.

Dependencies:   mbed TextLCD

Fork of I2C-LCD by Oscar de Jesus Vasquez

Files at this revision

API Documentation at this revision

Comitter:
bertonieto
Date:
Thu Apr 11 06:44:22 2019 +0000
Parent:
1:93d8becc35f9
Commit message:
u

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Wed May 25 16:11:32 2016 +0000
+++ b/main.cpp	Thu Apr 11 06:44:22 2019 +0000
@@ -2,51 +2,38 @@
 #include "TextLCD.h"
 #include <string>
 
-//ZONA DE PRUEBAS 
+
 
-//definimos la bascula para despues obtener el peso
-Serial serialBascula(p9, p10); //Tx,Rx
-
-//Iniciamos I2C Communication 
-I2C i2c_lcd(p28,p27); // SDA, SCL 
-TextLCD_I2C lcd(&i2c_lcd, 0x4E, TextLCD::LCD16x2, TextLCD::HD44780); // I2C bus, PCF8574 Slaveaddress, LCD Type, Device Type 
+//Iniciamos I2C Communication
+//I2C i2c_lcd(p28,p27); // SDA, SCL
+I2C i2c_lcd(p32, p31); // SDA, SCL
+TextLCD_I2C lcd(&i2c_lcd, 0x4E, TextLCD::LCD16x2, TextLCD::HD44780); // I2C bus, PCF8574 Slaveaddress, LCD Type, Device Type
 
 //Iniciamos el LCD.
-void iniciaLCD(){
+void iniciaLCD()
+{
     lcd.setMode(TextLCD::DispOn); //DispOff, DispOn
     lcd.setBacklight(TextLCD::LightOff);//LightOff, LightOn
     lcd.setCursor(TextLCD::CurOff_BlkOff);//CurOff_BlkOff, CurOn_BlkOff, CurOff_BlkOn, CurOn_BlkOn
-    }
+}
 
-int leerPeso(){
-    char buffer1[100];
-    string pesoss;
-    int ipesoss;
-    serialBascula.printf("2005002D:<CR><LF>\n");   //\r\n
-        if (serialBascula.readable()==true){
-            //serialBascula.gets(buffer1,20);        
-            pesoss = serialBascula.gets(buffer1,40);
-            pesoss = pesoss.substr(10,4);
-            strcpy(buffer1, pesoss.c_str());
-            ipesoss = atoi(buffer1);
+//Pintamos en el LCD linea 1.
+void pintaLCD1(bool manual){
+    if (manual){
+        lcd.locate(0,0);
+        lcd.printf("     MANUAL     ");
         }
-        return ipesoss;
+        else{
+            lcd.locate(0,0);
+            lcd.printf("Salida1  Salida2");
+            }
     }
     
 //Main, aqui ponemos todo el programa.
-int main(){
-    Serial pc(USBTX, USBRX);    
+int main()
+{
+    Serial pc(USBTX, USBRX);
     iniciaLCD(); //Iniciamos el LCD
-    int pesoreal;
-
-    while(1){
-        pesoreal = leerPeso();
-            lcd.locate(5,1);
-            lcd.printf("%d", pesoreal);
-        wait(1);
-        }
-    //rfid.printf("20050025:<CR><LF>");
-    //pc.printf("%s",rfid.getc());
-    //el problema viene cuando se intenta llamar a la funcion que devuelve el peso. a veces da error porque el peso no se puede cast-ear a int. No se poque ocurre este error ni como solventarlo.
-    //voy a mirar el tema en C++
-    }
\ No newline at end of file
+    pintaLCD1(0);
+    //printf
+}
\ No newline at end of file