![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
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@1:2377110920ce, 2020-02-07 (annotated)
- Committer:
- geogarcia
- Date:
- Fri Feb 07 00:09:10 2020 +0000
- Revision:
- 1:2377110920ce
- Parent:
- 0:fff27b50ca98
- Child:
- 2:0edb81388d5f
prueba
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
geogarcia | 1:2377110920ce | 1 | ////////////////////////////////// LIBRERIAS DEL PROYECTO///////////////////////////////////////////// |
geogarcia | 1:2377110920ce | 2 | |
geogarcia | 1:2377110920ce | 3 | #include "mbed.h"// libreria principal mbed |
geogarcia | 1:2377110920ce | 4 | #include "TextLCD.h"// libreria lcd |
geogarcia | 1:2377110920ce | 5 | #include "Keypad.h"// libreria Keypad |
geogarcia | 1:2377110920ce | 6 | #include "DHT11.h"// libreria sensor de humedad y temperatura |
geogarcia | 1:2377110920ce | 7 | |
geogarcia | 1:2377110920ce | 8 | ////////////////////////////////////////////////////////////////////////////////////////////////////// |
geogarcia | 1:2377110920ce | 9 | ///////////////////////////////// CONFIGURACION DE GPIO //////////////////////////////////////////// |
geogarcia | 1:2377110920ce | 10 | |
geogarcia | 1:2377110920ce | 11 | DigitalOut myled(PD_13);// configura salida digital y asigna a myled al pin d13 |
geogarcia | 1:2377110920ce | 12 | TextLCD lcd(PB_7,PB_8,PB_15,PB_14,PB_13,PB_12,TextLCD:: LCD16x2);// configuracion de conexion de lcd |
geogarcia | 1:2377110920ce | 13 | Keypad teclado(PC_8,PC_11,PC_7,PC_6,PB_0,PD_6,PD_7,PB_3); |
geogarcia | 1:2377110920ce | 14 | DHT11 dato(PC_5); |
geogarcia | 1:2377110920ce | 15 | ///////////////////////////////////////////////////////////////////////////////////////////////////// |
geogarcia | 1:2377110920ce | 16 | ////////////////////////// DECLARACION DE VARIABLES GLOBALES //////////////////////////////////// |
geogarcia | 0:fff27b50ca98 | 17 | |
geogarcia | 1:2377110920ce | 18 | int z; |
geogarcia | 1:2377110920ce | 19 | char key; |
geogarcia | 1:2377110920ce | 20 | int released; |
geogarcia | 1:2377110920ce | 21 | int s; // variable usada en rutina sensor |
geogarcia | 1:2377110920ce | 22 | int temp; |
geogarcia | 1:2377110920ce | 23 | int hum; |
geogarcia | 1:2377110920ce | 24 | /////////////////////////////////////////////////////////////////////////////////////////////////////// |
geogarcia | 1:2377110920ce | 25 | ////////////////////////////////////////// SUB-RUTina keypad///////////////////////////////////////////// |
geogarcia | 1:2377110920ce | 26 | void keypad1(){ |
geogarcia | 1:2377110920ce | 27 | |
geogarcia | 1:2377110920ce | 28 | key=teclado.ReadKey(); |
geogarcia | 1:2377110920ce | 29 | if(key== '\0') |
geogarcia | 1:2377110920ce | 30 | released=1; |
geogarcia | 1:2377110920ce | 31 | if((key!= '\0')&& (released==1)){ |
geogarcia | 1:2377110920ce | 32 | //lcd.printf("%c\n",key); |
geogarcia | 1:2377110920ce | 33 | released=0; |
geogarcia | 1:2377110920ce | 34 | } |
geogarcia | 1:2377110920ce | 35 | } |
geogarcia | 1:2377110920ce | 36 | |
geogarcia | 1:2377110920ce | 37 | /////////////////////////////////////////////////////////////////////////////////////////////////////// |
geogarcia | 1:2377110920ce | 38 | ////////////////////////////////////////// SUB-RUTina SENSORE DHT11///////////////////////////////////////////// |
geogarcia | 1:2377110920ce | 39 | void sensor(){ |
geogarcia | 1:2377110920ce | 40 | s=dato.readData(); |
geogarcia | 1:2377110920ce | 41 | if (s != DHT11::OK){ |
geogarcia | 1:2377110920ce | 42 | lcd.printf("ERROR SENSOR\r\n"); |
geogarcia | 1:2377110920ce | 43 | } |
geogarcia | 1:2377110920ce | 44 | else{ |
geogarcia | 1:2377110920ce | 45 | lcd.cls(); |
geogarcia | 1:2377110920ce | 46 | return; |
geogarcia | 1:2377110920ce | 47 | |
geogarcia | 1:2377110920ce | 48 | |
geogarcia | 1:2377110920ce | 49 | } |
geogarcia | 1:2377110920ce | 50 | |
geogarcia | 1:2377110920ce | 51 | |
geogarcia | 1:2377110920ce | 52 | } |
geogarcia | 1:2377110920ce | 53 | |
geogarcia | 1:2377110920ce | 54 | /////////////////////////////////////////////////////////////////////////////////////////////////////// |
geogarcia | 1:2377110920ce | 55 | ////////////////////////////////////////// SUB-RUTINA MENU///////////////////////////////////////////// |
geogarcia | 1:2377110920ce | 56 | void menu(){ |
geogarcia | 1:2377110920ce | 57 | while(1){ |
geogarcia | 1:2377110920ce | 58 | |
geogarcia | 1:2377110920ce | 59 | keypad1(); |
geogarcia | 1:2377110920ce | 60 | if(key=='D' ){ |
geogarcia | 1:2377110920ce | 61 | lcd.cls(); |
geogarcia | 1:2377110920ce | 62 | return; |
geogarcia | 1:2377110920ce | 63 | } |
geogarcia | 1:2377110920ce | 64 | //void inicial(); |
geogarcia | 1:2377110920ce | 65 | |
geogarcia | 1:2377110920ce | 66 | lcd.locate(0,0);// LOCALIZA INICIO DE TEXTO EN COLUMNAS Y FILAS |
geogarcia | 1:2377110920ce | 67 | lcd.printf( " Menu " ); |
geogarcia | 1:2377110920ce | 68 | lcd.locate(0,1); |
geogarcia | 1:2377110920ce | 69 | lcd.printf( " Configuracion " ); |
geogarcia | 1:2377110920ce | 70 | //wait(3); |
geogarcia | 1:2377110920ce | 71 | //lcd.cls();//borra caracters |
geogarcia | 1:2377110920ce | 72 | |
geogarcia | 1:2377110920ce | 73 | } |
geogarcia | 1:2377110920ce | 74 | |
geogarcia | 1:2377110920ce | 75 | } |
geogarcia | 1:2377110920ce | 76 | |
geogarcia | 1:2377110920ce | 77 | /////////////////////////////////////////////////////////////////////////////////////////////////////// |
geogarcia | 1:2377110920ce | 78 | //////////////////////////////////// SUB-RUTINA INICIAL /////////////////////////////////////////////// |
geogarcia | 1:2377110920ce | 79 | void inicial(){ |
geogarcia | 1:2377110920ce | 80 | while(1){ |
geogarcia | 1:2377110920ce | 81 | //lcd.cls(); |
geogarcia | 1:2377110920ce | 82 | keypad1(); |
geogarcia | 1:2377110920ce | 83 | |
geogarcia | 1:2377110920ce | 84 | if ( key=='A'){ |
geogarcia | 1:2377110920ce | 85 | lcd.cls(); //borra caracters |
geogarcia | 1:2377110920ce | 86 | menu(); |
geogarcia | 1:2377110920ce | 87 | } |
geogarcia | 1:2377110920ce | 88 | |
geogarcia | 1:2377110920ce | 89 | sensor(); |
geogarcia | 1:2377110920ce | 90 | |
geogarcia | 1:2377110920ce | 91 | |
geogarcia | 1:2377110920ce | 92 | //temp:dato.readTemperature(); |
geogarcia | 1:2377110920ce | 93 | //hum: dato.readHumidity(); |
geogarcia | 1:2377110920ce | 94 | lcd.locate(0,0); // LOCALIZA INICIO DE TEXTO EN COLUMNAS Y FILAS |
geogarcia | 1:2377110920ce | 95 | lcd.printf( "T :%d C SP: 40",dato.readTemperature()); |
geogarcia | 1:2377110920ce | 96 | lcd.locate(0,1); |
geogarcia | 1:2377110920ce | 97 | lcd.printf( "Hr:%d hr SP: 75 ",dato.readHumidity()); |
geogarcia | 1:2377110920ce | 98 | //wait(0.1); |
geogarcia | 1:2377110920ce | 99 | |
geogarcia | 1:2377110920ce | 100 | } // cierra while |
geogarcia | 1:2377110920ce | 101 | } // cierra rutina |
geogarcia | 0:fff27b50ca98 | 102 | |
geogarcia | 1:2377110920ce | 103 | ///////////////////////////////////////////////////////////////////////////////////////////////////// |
geogarcia | 1:2377110920ce | 104 | //////////////////////////////////// RUTINA PRINCIPAL ////////////////////////////////////////////// |
geogarcia | 0:fff27b50ca98 | 105 | int main() { |
geogarcia | 1:2377110920ce | 106 | z=0; |
geogarcia | 1:2377110920ce | 107 | released=1; |
geogarcia | 1:2377110920ce | 108 | //lcd.printf("helllooo people");// escribe caracteres en el lcd |
geogarcia | 1:2377110920ce | 109 | |
geogarcia | 0:fff27b50ca98 | 110 | while(1) { |
geogarcia | 1:2377110920ce | 111 | // lcd.cls();//borra caracters |
geogarcia | 1:2377110920ce | 112 | lcd.locate(0,0);// LOCALIZA INICIO DE TEXTO EN COLUMNAS Y FILAS |
geogarcia | 1:2377110920ce | 113 | lcd.printf( " Proyecto " ); |
geogarcia | 1:2377110920ce | 114 | lcd.locate(0,1); |
geogarcia | 1:2377110920ce | 115 | lcd.printf( " Tutoria " ); |
geogarcia | 1:2377110920ce | 116 | wait(3); |
geogarcia | 1:2377110920ce | 117 | lcd.cls();//borra caracters |
geogarcia | 1:2377110920ce | 118 | lcd.locate(0,0); |
geogarcia | 1:2377110920ce | 119 | lcd.printf( " Sistemas " ); |
geogarcia | 1:2377110920ce | 120 | lcd.locate(0,1); |
geogarcia | 1:2377110920ce | 121 | lcd.printf( "Microprocesados " ); |
geogarcia | 1:2377110920ce | 122 | wait(3); |
geogarcia | 1:2377110920ce | 123 | lcd.cls();//borra caracters |
geogarcia | 1:2377110920ce | 124 | inicial(); |
geogarcia | 1:2377110920ce | 125 | |
geogarcia | 1:2377110920ce | 126 | } |
geogarcia | 1:2377110920ce | 127 | |
geogarcia | 0:fff27b50ca98 | 128 | } |
geogarcia | 1:2377110920ce | 129 | |
geogarcia | 1:2377110920ce | 130 | /////////////////////////////////////////////////////////////////////////////////////////////////////// |
geogarcia | 1:2377110920ce | 131 | |
geogarcia | 1:2377110920ce | 132 | |
geogarcia | 1:2377110920ce | 133 |