Control On-Off Keypad LCD
Dependencies: Keypad TextLCD mbed
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(PTC4,PTC3,PTC0,PTC7,PTC11,PTC10,PTC6,PTC5); // 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 wait(1); 00033 lcd.cls(); 00034 while(i<=2){ 00035 read_kpad(); 00036 if(key!='\0'){ 00037 if(i==0){centenas=key-48;lcd.locate(1,1);lcd.printf("%c",key);if(centenas>1){centenas=1;}} 00038 if(i==1){decenas=key-48;lcd.locate(2,1);lcd.printf("%c",key);} 00039 if(i==2){unidades=key-48;lcd.locate(3,1);lcd.printf("%c",key);} 00040 ++i;} 00041 } 00042 wait(0.25); 00043 setpoint=unidades+10.0*decenas+100.0*centenas; 00044 lcd.cls(); 00045 lcd.locate(1,1); 00046 lcd.printf("SP: %fdegC ",setpoint); 00047 wait(1); 00048 lcd.cls(); 00049 lcd.locate(1,1); 00050 lcd.printf("SETUP OK"); 00051 wait(1); 00052 } 00053 00054 00055 00056 00057 int main() 00058 { 00059 00060 rs232.printf("Control ON-OFF \n\r"); 00061 lcd.printf("Control ON-OFF \r\n"); 00062 wait(1); 00063 lcd.cls(); 00064 00065 while (1) { 00066 valor_adc=AnalogPin.read()*5; 00067 lcd.locate(1,1); 00068 lcd.printf("SP; %fdegC ",setpoint); 00069 lcd.locate(1,2); 00070 lcd.printf("PV; %fdegC ",valor_adc); 00071 rs232.printf("%f,%f",setpoint,valor_adc); 00072 00073 read_kpad(); 00074 if(key=='*') { 00075 setup_pyrom(); 00076 } 00077 00078 if(valor_adc>=setpoint) { 00079 pinOut=0; 00080 } else { 00081 pinOut=1;; 00082 } 00083 00084 00085 } 00086 }
Generated on Tue Jul 12 2022 21:29:58 by 1.7.2