teclas que funcionan
Dependencies: Debounced TextLCD mbed
Fork of tarea1 by
main.cpp
00001 #include "mbed.h" 00002 #include "DebouncedIn.h" 00003 #include "TextLCD.h" 00004 00005 AnalogIn Vin(PTC2); 00006 TextLCD lcd(PTB10, PTB11, PTE2, PTE3, PTE4, PTE5); // rs, e, d4-d7 00007 00008 DigitalOut led1(LED1); 00009 DigitalOut led2(LED2); 00010 DigitalOut led3(LED3); 00011 DebouncedIn button1(PTC12); 00012 DebouncedIn button2(PTC13); 00013 DebouncedIn button3(PTC16); 00014 00015 int C1=0x0F; 00016 int sp=0,kp=0,kd=0,ki=0,p=1; 00017 int main() 00018 { 00019 lcd.cls(); 00020 lcd.writeCommand(C1);//escribimos un comando segun el manual del modulo LCD 00021 lcd.locate(8,0); 00022 lcd.printf("kp=%d", kp); 00023 lcd.locate(0,1); 00024 lcd.printf("Ki=%d", ki); 00025 lcd.locate(8,1); 00026 lcd.printf("Kd=%d", kd); 00027 lcd.locate(0,0); 00028 lcd.printf("Sp=%d", sp); 00029 00030 while(1) 00031 { 00032 if (button1.falling()) 00033 { 00034 led1 =!led1; 00035 if (p==1) 00036 { 00037 ++sp; 00038 lcd.locate(3,0); 00039 lcd.printf(" "); 00040 lcd.locate(3,0); 00041 lcd.printf("%d", sp); 00042 } 00043 else if (p==2) 00044 { 00045 ++kp; 00046 lcd.locate(11,0); 00047 lcd.printf(" "); 00048 lcd.locate(11,0); 00049 lcd.printf("%d", kp); 00050 } 00051 else if (p==3) 00052 { 00053 ++ki; 00054 lcd.locate(3,1); 00055 lcd.printf(" "); 00056 lcd.locate(3,1); 00057 lcd.printf("%d", ki); 00058 } 00059 else if (p==4) 00060 { 00061 ++kd; 00062 lcd.locate(11,1); 00063 lcd.printf(" "); 00064 lcd.locate(11,1); 00065 lcd.printf("%d", kd); 00066 } 00067 } 00068 if (button2.falling()) 00069 { 00070 led2 =!led2; 00071 if (p==1) 00072 { 00073 if (sp==0) // no mostrar nada 00074 { 00075 } 00076 else 00077 { 00078 --sp; 00079 lcd.locate(3,0); 00080 lcd.printf(" "); 00081 lcd.locate(3,0); 00082 lcd.printf("%d", sp); 00083 } 00084 } 00085 if (p==2) 00086 { 00087 if (kp==0) // no mostrar nada 00088 { 00089 } 00090 else 00091 { 00092 --kp; 00093 lcd.locate(11,0); 00094 lcd.printf(" "); 00095 lcd.locate(11,0); 00096 lcd.printf("%d", kp); 00097 } 00098 } 00099 if (p==3) 00100 { 00101 if (ki==0) // no mostrar nada 00102 { 00103 } 00104 else 00105 { 00106 --ki; 00107 lcd.locate(3,1); 00108 lcd.printf(" "); 00109 lcd.locate(3,1); 00110 lcd.printf("%d", ki); 00111 } 00112 } 00113 if (p==4) 00114 { 00115 if (kd==0) // no mostrar nada 00116 { 00117 } 00118 else 00119 { 00120 --kd; 00121 lcd.locate(11,1); 00122 lcd.printf(" "); 00123 lcd.locate(11,1); 00124 lcd.printf("%d", kd); 00125 } 00126 } 00127 } 00128 if (button3.falling()) 00129 { 00130 led3 =!led3; 00131 if (p==1) 00132 { 00133 ++p; 00134 lcd.locate(11,0); 00135 lcd.printf("%d", kp); 00136 00137 00138 } 00139 else if (p==2) 00140 { 00141 ++p; 00142 lcd.locate(3,1); 00143 lcd.printf("%d", ki); 00144 lcd.locate(3,1); 00145 00146 } 00147 else if (p==3) 00148 { 00149 ++p; 00150 lcd.locate(11,1); 00151 lcd.printf("%d", kd); 00152 00153 00154 } 00155 else if (p==4) 00156 { 00157 p=1; 00158 lcd.locate(3,0); 00159 lcd.printf("%d", sp); 00160 00161 00162 } 00163 } 00164 } 00165 }
Generated on Sun Jul 31 2022 11:28:00 by 1.7.2