Alberto Nieto / Mbed 2 deprecated BasculaDeCebo

Dependencies:   mbed TextLCD

Fork of I2C-LCD by Oscar de Jesus Vasquez

Files at this revision

API Documentation at this revision

Comitter:
bertonieto
Date:
Wed May 25 16:11:32 2016 +0000
Parent:
0:376d7a150177
Child:
2:8db024073f1f
Commit message:
Programa de gestion de bascula con LCD por i2c.

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Wed Dec 03 03:48:48 2014 +0000
+++ b/main.cpp	Wed May 25 16:11:32 2016 +0000
@@ -1,20 +1,52 @@
 #include "mbed.h"
 #include "TextLCD.h"
-//Incluye resistencias de 2.2K en los pines de i2c a 3.3
- 
+#include <string>
 
+//ZONA DE PRUEBAS 
 
-// I2C Communication
-I2C i2c_lcd(p28,p27); // SDA, SCL
- 
+//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 el LCD.
+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 main() 
-{
-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
-lcd.printf("Oscar de Jesus \n Vasquez");
- 
- }
\ No newline at end of file
+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);
+        }
+        return ipesoss;
+    }
+    
+//Main, aqui ponemos todo el programa.
+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
--- a/mbed.bld	Wed Dec 03 03:48:48 2014 +0000
+++ b/mbed.bld	Wed May 25 16:11:32 2016 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/552587b429a1
\ No newline at end of file
+http://mbed.org/users/mbed_official/code/mbed/builds/252557024ec3
\ No newline at end of file