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 I2CLCD TextLCD
Revision 2:eba513d94574, committed 2020-02-13
- Comitter:
- ramirezcar
- Date:
- Thu Feb 13 02:12:38 2020 +0000
- Parent:
- 1:9c84e7a34b10
- Child:
- 3:f045443dff50
- Commit message:
- con visualizacion de valores por pantalla via I2C
Changed in this revision
| TextLCD.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 |
--- a/TextLCD.lib Sat Feb 08 05:53:07 2020 +0000 +++ b/TextLCD.lib Thu Feb 13 02:12:38 2020 +0000 @@ -1,1 +1,1 @@ -https://os.mbed.com/users/simon/code/TextLCD/#308d188a2d3a +https://os.mbed.com/users/lscordovar/code/TextLCD/#baf112053ac8
--- a/main.cpp Sat Feb 08 05:53:07 2020 +0000
+++ b/main.cpp Thu Feb 13 02:12:38 2020 +0000
@@ -1,13 +1,25 @@
// Voltimetro DC con STM32
//Carlos Ramírez Quiroga
//3.02.2020
-//Utiliza divisor de voltaje para obtener valores
-
+//Utiliza divisor de voltaje para obtener valores a ser medidos
#include "mbed.h"
#include "TextLCD.h" // Incluye la libreria para LCD
-TextLCD lcd(PC_8, PC_9, PD_3, PD_6, PD_11, PD_12); //Inicilizar la pantalla LCD (se considera una pantalla de 16 caracteres X 2 Filas
+#define DEFAULT 0//no
+#define ADAFRUIT 0//no
+#define DFROBOT 0
+#define LCM1602 0
+#define YWROBOT 0
+#define GYLCD 0//no
+#define MJKDZ 0//no
+#define SYDZ 1
+#define WIDEHK 0//no
+#define LCDPLUG 0//no
+
+//TextLCD lcd(PC_8, PC_9, PD_3, PD_6, PD_11, PD_12); //Inicilizar la pantalla LCD (se considera una pantalla de 16 caracteres X 2 Filas
AnalogIn ain(PB_0);// Inicializar pin PB_0 como entrada análoga
Serial device(PA_2,PA_3,115200);
+I2C i2c_lcd(PB_9, PB_8); // SDA, SCL
+TextLCD_I2C lcd(&i2c_lcd, 0x4E, TextLCD::LCD20x4);
double vin=0.0;//voltaje de entrada a ser medido
double vout=0.0; //voltaje en entrada análoga
@@ -15,21 +27,54 @@
float R2=100000;//100 Kohms
float value=0;
-
-int main()
-
-{
+void setup(){
+ lcd.setBacklight(TextLCD::LightOn); // Retroiluminación de pantalla
+ lcd.setCursor(TextLCD::CurOff_BlkOn);//Seteo cursor
+ lcd.setUDC(0, (char *) udc_0);
+ lcd.putc(0);
+ lcd.setUDC(1, (char *) udc_1);
+ lcd.putc(1);
+ lcd.cls();//limpia pantalla
+ int col = 0;//definición columna
+ int row = 0;//definición fila
+ lcd.locate(col,row);//Ubiación del cursor
+ lcd.printf("Inicializando...");// mensaje de Inicialización de pantalla
+ wait(2);//Espere 2 segundos
+ //Secuencia de Incilización
+ row++;
+ lcd.locate(col,row);
+ lcd.printf("Inicializando...");
+ wait(2);
+ row++;
+ lcd.locate(col,row);
+ lcd.printf("Inicializando...");
+ wait(2);
+ row++;
+ lcd.locate(col,row);
+ lcd.printf("Inicializando...");
+}
+void mostrar(double vin){
+ lcd.setBacklight(TextLCD::LightOn);
+ lcd.cls();
+ lcd.locate(0, 0);
+ lcd.printf("Voltaje de Entrada:");
+ lcd.locate(0, 1);
+ lcd.printf("%2.2f", vin);
+}
+int main(){
+ setup();
while (1) {
value=ain; //Lectura de entrada analoga escogida para divisor de voltaje
- device.printf ("INPUT V=%2.2f\r\n",ain);//Lectura entrada análoga puerto serial
- vout=(value*3.3)/4096;//formula para convertir el valor de ADC a voltios
+ device.printf ("ain V=%2.2f\r\n",value);//Lectura entrada análoga puerto serial
+ vout=(value*3.0);//formula para convertir el valor de ADC a voltios
+ device.printf ("vout V=%2.8f\r\n",vout);//Lectura entrada análoga puerto serial
vin=vout/(R2/(R1+R2));//formula del voltaje de entrada a ser leído
+ device.printf ("vin V=%2.8f\r\n",vin);//Lectura entrada análoga puerto serial
if(vin<0.09) {
vin=0.0;//si el voltaje leído es menor a 0.09 Vcc sete en 0 el valor de Vin
-
+ device.printf ("xxxx\r\n");
}
- device.printf("INPUT V=%2.2f\r\n",vin);//Imprima puerto serial
- lcd.printf("INPUT V=%2.2f\r\n",vin);//Imprima en segunda línea de LCD
+ mostrar(vin);
wait(0.5);//espere 0,5 segundos
}
}