ESTE ES UN PROGRAMA PARA EL CONTROL DE NIVEL Y TEMPERATURA CON INDICACIÓN DE NIVELES Y GENERACIÓN DE ALARMAS

Dependencies:   mbed TextLCD

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"       // llamado a la libreria mbed
00002 #include "nivel.h"
00003 #include "temperatura.h"
00004 #include "TextLCD.h"
00005 
00006 //Entradas digitales
00007 DigitalIn Pulsador(PA_0);
00008 
00009 //Salidas digitales
00010 DigitalOut led_naranja(PD_13);
00011 DigitalOut led_verde(PD_12);
00012 DigitalOut led_rojo(PD_14);
00013 DigitalOut led_azul(PD_15);
00014 
00015 //Entradas analogicas
00016 AnalogIn ain1(PC_1);
00017 AnalogIn ain2(PC_2);
00018 
00019 //Interrupciones
00020 Ticker flipper1;
00021 Ticker flipper2;
00022 
00023 //Variables auxiliares
00024 bool seleccion_visualizador=0;
00025 int i=0;
00026 float sensor1=0.0;
00027 float sensor2=0.0;
00028 
00029 //Comunicacion
00030 Serial device (PA_2,PA_3,115200);
00031 
00032 //LCD
00033 TextLCD lcd(PB_7, PB_8, PB_15, PB_14, PB_13, PB_12);
00034 
00035 void flip1()   // flip 1 function
00036 {
00037     sensor1 = ain1*100;
00038     device.printf("Nivel: %0.1f%%\n", sensor1);
00039 }
00040 
00041 void flip2()   // flip 2 function
00042 {
00043     sensor2 = ain2*100;
00044     device.printf("Temp: %0.1f grados Celsius%\n", sensor2);
00045 }
00046 
00047 int main()
00048 {
00049     flipper1.attach(&flip1, 1.0); // cada segundo
00050     flipper2.attach(&flip2, 1.0); // cada segundo
00051 
00052     while(1) {
00053         seleccion_visualizador=Pulsador.read();
00054 
00055 //        device.printf("Nivel en porcentaje: %0.1f%%\n", sensor1()*1);
00056         nivel();
00057         temperatura();
00058 
00059         if(Pulsador == 1) {                     //Prueba de pulsador
00060             i++;
00061             if (i>1) i=0;
00062         }
00063         if (i==0) {
00064             lcd.locate(0,0);
00065             lcd.printf(" Nivel: %2.2f%\n",sensor1);
00066             lcd.printf(" Temp.: %2.2f%\n",sensor2);
00067         }
00068         if (i==1) {
00069             lcd.locate(0,0);
00070             lcd.printf(" Temp.: %2.2f%\n",sensor2);
00071             lcd.printf(" Nivel: %2.2f%\n",sensor1);
00072         }
00073         wait(1);
00074     }
00075 }