ESTE PROGRAMA VA A CONTROLAR LAS VARIABLES DE HUMEDAD Y TEMPERATURA SET POINT POR EL USUARIO A TRAVES DE UNA INTERFAZ

Dependencies:   mbed TextLCD Keypad DS1307 DHT11

main.cpp

Committer:
geogarcia
Date:
2020-02-07
Revision:
1:2377110920ce
Parent:
0:fff27b50ca98
Child:
2:0edb81388d5f

File content as of revision 1:2377110920ce:

////////////////////////////////// LIBRERIAS DEL PROYECTO/////////////////////////////////////////////

#include "mbed.h"// libreria principal mbed
#include "TextLCD.h"// libreria lcd
#include "Keypad.h"// libreria Keypad
#include "DHT11.h"// libreria sensor de humedad y temperatura

//////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////  CONFIGURACION DE  GPIO ////////////////////////////////////////////

DigitalOut myled(PD_13);// configura salida digital y asigna a myled al pin d13
TextLCD lcd(PB_7,PB_8,PB_15,PB_14,PB_13,PB_12,TextLCD:: LCD16x2);// configuracion de conexion de lcd
Keypad  teclado(PC_8,PC_11,PC_7,PC_6,PB_0,PD_6,PD_7,PB_3);
DHT11 dato(PC_5);
/////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////     DECLARACION DE VARIABLES GLOBALES ////////////////////////////////////

int z;
char key;
int released;
int s; // variable usada en rutina sensor 
int temp;
int hum;
///////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////// SUB-RUTina keypad/////////////////////////////////////////////
     void keypad1(){
       
        key=teclado.ReadKey();
        if(key== '\0')
          released=1;
        if((key!= '\0')&& (released==1)){
            //lcd.printf("%c\n",key);
            released=0;
            }               
    }
          
/////////////////////////////////////////////////////////////////////////////////////////////////////// 
////////////////////////////////////////// SUB-RUTina SENSORE DHT11/////////////////////////////////////////////
     void sensor(){
        s=dato.readData();
        if (s != DHT11::OK){
            lcd.printf("ERROR SENSOR\r\n");
        }    
        else{
           lcd.cls();
           return;
         
            
        }
       
        
    }
          
/////////////////////////////////////////////////////////////////////////////////////////////////////// 
////////////////////////////////////////// SUB-RUTINA MENU/////////////////////////////////////////////
 void menu(){
      while(1){
          
        keypad1();
        if(key=='D' ){
        lcd.cls();
        return;
        }
        //void inicial();
         
        lcd.locate(0,0);// LOCALIZA INICIO DE TEXTO EN COLUMNAS  Y FILAS
        lcd.printf( "      Menu  " );
        lcd.locate(0,1);
        lcd.printf( "  Configuracion " );
        //wait(3);
        //lcd.cls();//borra caracters
             
       }           
          
    }
          
///////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////// SUB-RUTINA INICIAL ///////////////////////////////////////////////
 void inicial(){
   while(1){
        //lcd.cls();
        keypad1();
        
       if ( key=='A'){
         lcd.cls();                        //borra caracters
         menu();
         }
         
       sensor();
      
           
       //temp:dato.readTemperature();
       //hum: dato.readHumidity();   
       lcd.locate(0,0);                   // LOCALIZA INICIO DE TEXTO EN COLUMNAS  Y FILAS
       lcd.printf( "T :%d C  SP: 40",dato.readTemperature());
       lcd.locate(0,1);
       lcd.printf( "Hr:%d hr SP: 75 ",dato.readHumidity());
       //wait(0.1);
            
        }                                 // cierra while
}                                        //  cierra rutina

/////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////// RUTINA  PRINCIPAL //////////////////////////////////////////////
int main() {
    z=0;
    released=1;
    //lcd.printf("helllooo people");// escribe caracteres en el lcd 
    
    while(1) {
   //  lcd.cls();//borra caracters
      lcd.locate(0,0);// LOCALIZA INICIO DE TEXTO EN COLUMNAS  Y FILAS
      lcd.printf( "    Proyecto " );
      lcd.locate(0,1);
      lcd.printf( "    Tutoria " );
       wait(3);
      lcd.cls();//borra caracters
      lcd.locate(0,0);
      lcd.printf( "    Sistemas " );
      lcd.locate(0,1);
      lcd.printf( "Microprocesados " );
      wait(3);
      lcd.cls();//borra caracters
      inicial();
     
      }      
        
    }
     
///////////////////////////////////////////////////////////////////////////////////////////////////////