voltimetro LCD, 7seg_4digitos

Dependencies:   mbed TextLCD

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "TextLCD.h"
00003 
00004 TextLCD lcd(A0,A1,A2,A3,A4,A5,TextLCD::LCD16x2);
00005 AnalogIn entrada(PC_3);//pin entrada analogica
00006 DigitalOut led (LED1);
00007 int voltaje;
00008 int entero, decimal;
00009 double volt_in;
00010 
00011 BusOut display(PA_10,PB_3,PB_5,PB_4,PB_10,PA_8,PA_9);//pines en la placa
00012 BusOut Trans(PB_13,PB_14); //pin para los transistores, entrada Volt7seg
00013 DigitalOut Indecimal (PC_7);//punto decimal
00014 void ver();
00015 void incre();
00016 int decimas;
00017 int conteo;
00018 const char seg[10]= {0x40,0x79,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};
00019 Ticker visualizar;
00020 Ticker incrementar;
00021 
00022 
00023 void ver()
00024 {
00025     switch(conteo) {
00026         case 0:
00027             display =0x00;
00028             Trans =0;
00029             break;
00030         case 1:
00031             display = seg[decimas];
00032             Trans=1;
00033             break;
00034         case 2:
00035             display =0x00;
00036             Trans =0;
00037             break;
00038         case 3:
00039             display = seg[entero];
00040             Trans=2;
00041             break;
00042     }
00043     conteo++;
00044     if(conteo==4) {
00045         conteo=0;
00046     }
00047 }
00048 
00049 
00050 
00051 void incre()
00052 {
00053 
00054             volt_in= entrada.read();
00055         volt_in = volt_in*3300;
00056         voltaje = int(volt_in);
00057         entero = voltaje/1000;
00058         decimal = voltaje%1000;
00059         decimas = decimal/100;
00060 }
00061 
00062 
00063 
00064 int main()
00065 {
00066     //lcd.cls();
00067     //lcd.printf("Su Voltaje es:");
00068     visualizar.attach(&ver,5.5e-3);
00069     incrementar.attach(&incre,1);
00070 
00071 
00072 
00073     while(1) {
00074         volt_in= entrada.read();
00075         volt_in = volt_in*3300;
00076         voltaje = int(volt_in);
00077         entero = voltaje/1000;
00078         decimal = voltaje%1000;
00079         led=1;
00080         lcd.cls();
00081         lcd.printf("El Voltaje es:");
00082         lcd.locate(1,5);
00083         lcd.printf("%01d,%03d volts", entero,decimal);//de la parte enteraimprime 1 digito y decima imprime 3
00084         wait_us(1e6);
00085         led=1;
00086 
00087     }
00088 }