control de temperatura por medio de un sensor LM35
Dependencies: Keypad TextLCD mbed
Fork of control_onoff by
main.cpp
00001 #include "mbed.h" 00002 #include "TextLCD.h" 00003 #include "Keypad.h" 00004 00005 Serial rs232(USBTX, USBRX); 00006 AnalogIn AnalogPin(PTB0); 00007 DigitalOut pinOut(PTB1); 00008 00009 TextLCD lcd(PTE20,PTE21,PTE22,PTE23,PTE29,PTE30, TextLCD::LCD16x2); // Rs, E, d4, d5, d6, d7, RW=GND 00010 Keypad keypad(PTB11,PTB10,PTB9,PTB8,PTE5,PTE4,PTE3,PTE2); // c1, c2, c3, c4, f1, f2, f3, f4 00011 00012 char key; 00013 int released=1,unidades,decenas,centenas; 00014 float setpoint,valor_adc; 00015 00016 void read_kpad() 00017 { 00018 key=keypad.ReadKey(); 00019 if(key=='\0') released=1; 00020 if((key!='\0') && (released==1)) { 00021 released=0; 00022 } 00023 00024 } 00025 00026 void setup_pyrom() 00027 { 00028 int i=0; 00029 lcd.cls(); 00030 lcd.locate(1,1); 00031 lcd.printf("SETUP..."); 00032 rs232.printf("SETUP..."); 00033 wait(1); 00034 lcd.cls(); 00035 while(i<=2){ 00036 read_kpad(); 00037 wait(0.5); 00038 if(key!='\0'){ 00039 if(i==0){centenas=key-48;lcd.locate(1,1);lcd.printf("%c",key);if(centenas>1){centenas=1;}} 00040 if(i==1){decenas=key-48;lcd.locate(2,1);lcd.printf("%c",key);} 00041 if(i==2){unidades=key-48;lcd.locate(3,1);lcd.printf("%c",key);} 00042 ++i;} 00043 } 00044 wait(0.25); 00045 setpoint=unidades+10.0*decenas+100.0*centenas; 00046 lcd.cls(); 00047 lcd.locate(1,1); 00048 lcd.printf("SP: %fdegC ",setpoint); 00049 rs232.printf("SP: %fdegC ",setpoint); 00050 wait(1); 00051 lcd.cls(); 00052 lcd.locate(1,1); 00053 lcd.printf("SETUP OK"); 00054 rs232.printf("SETUP OK"); 00055 wait(1); 00056 } 00057 00058 int main() 00059 { 00060 rs232.baud(115200); 00061 rs232.printf("Control ON-OFF \n\r"); 00062 lcd.printf("Control ON-OFF \r\n"); 00063 wait(1); 00064 lcd.cls(); 00065 00066 while (1) { 00067 valor_adc=AnalogPin.read()*300;//guardar en entero y mostrar el enetero 00068 lcd.locate(1,1); 00069 lcd.printf("SP; %fdegC ",setpoint); 00070 lcd.locate(1,2); 00071 lcd.printf("PV; %fdegC ",valor_adc); 00072 rs232.printf("%f,%f \r \n",setpoint,valor_adc); 00073 00074 read_kpad(); 00075 if(key=='*') { 00076 setup_pyrom(); 00077 } 00078 00079 if(valor_adc>=setpoint) { 00080 pinOut=0; 00081 } else { 00082 pinOut=1;; 00083 } 00084 wait(0.3); 00085 00086 } 00087 }
Generated on Thu Jul 14 2022 19:35:09 by 1.7.2