Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: Debounced TextLCD mbed
Fork of pid_teclas by
main.cpp
00001 //Este programa se basó en el programa de tony63 teclas_PID 00002 00003 00004 //Julian Esteban Palacio Hernandez 00005 //Andres Mauricio Gomez Arevalo 00006 00007 #include "mbed.h" 00008 #include "DebouncedIn.h" 00009 #include "TextLCD.h" 00010 00011 AnalogIn Vin(PTC2); 00012 TextLCD lcd(PTB10, PTB11, PTE2, PTE3, PTE4, PTE5); // rs, e, d4-d7 00013 00014 DigitalOut led1(LED1); 00015 DigitalOut led2(LED2); 00016 DigitalOut led3(LED3); 00017 DebouncedIn button1(PTC12); 00018 DebouncedIn button2(PTC13); 00019 DebouncedIn button3(PTC16); 00020 00021 PwmOut Sonido(PTA5); 00022 00023 00024 float periodo; 00025 float Frecuencia=1000; 00026 int C1=0x0F; 00027 int sp=0,kp=0,kd=0,ki=0,p=1; 00028 int main() 00029 { 00030 lcd.cls(); 00031 lcd.writeCommand(C1);//escribimos un comando segun el manual del modulo LCD 00032 lcd.locate(8,0); 00033 lcd.printf("kp=%d", kp); 00034 lcd.locate(0,1); 00035 lcd.printf("Ki=%d", ki); 00036 lcd.locate(8,1); 00037 lcd.printf("Kd=%d", kd); 00038 lcd.locate(0,0); 00039 lcd.printf("Sp=%d", sp); 00040 00041 while(1) 00042 { 00043 00044 periodo=(1/Frecuencia); 00045 Sonido.period(periodo); 00046 00047 00048 if (button1.falling()) 00049 { 00050 00051 Sonido.write(0.5); 00052 wait(0.1); 00053 Sonido.write(0); 00054 led1 =!led1; 00055 if (p==1) 00056 { 00057 ++sp; 00058 lcd.locate(3,0); 00059 lcd.printf(" "); 00060 lcd.locate(3,0); 00061 lcd.printf("%d", sp); 00062 } 00063 else if (p==2) 00064 { 00065 ++kp; 00066 lcd.locate(11,0); 00067 lcd.printf(" "); 00068 lcd.locate(11,0); 00069 lcd.printf("%d", kp); 00070 } 00071 else if (p==3) 00072 { 00073 ++ki; 00074 lcd.locate(3,1); 00075 lcd.printf(" "); 00076 lcd.locate(3,1); 00077 lcd.printf("%d", ki); 00078 } 00079 else if (p==4) 00080 { 00081 ++kd; 00082 lcd.locate(11,1); 00083 lcd.printf(" "); 00084 lcd.locate(11,1); 00085 lcd.printf("%d", kd); 00086 } 00087 } 00088 if (button2.falling()) 00089 { 00090 00091 Sonido.write(0.5); 00092 wait(0.1); 00093 Sonido.write(0); 00094 led2 =!led2; 00095 if (p==1) 00096 { 00097 if (sp==0) // no mostrar nada 00098 { 00099 } 00100 else 00101 { 00102 --sp; 00103 lcd.locate(3,0); 00104 lcd.printf(" "); 00105 lcd.locate(3,0); 00106 lcd.printf("%d", sp); 00107 } 00108 } 00109 if (p==2) 00110 { 00111 if (kp==0) // no mostrar nada 00112 { 00113 } 00114 else 00115 { 00116 --kp; 00117 lcd.locate(11,0); 00118 lcd.printf(" "); 00119 lcd.locate(11,0); 00120 lcd.printf("%d", kp); 00121 } 00122 } 00123 if (p==3) 00124 { 00125 if (ki==0) // no mostrar nada 00126 { 00127 } 00128 else 00129 { 00130 --ki; 00131 lcd.locate(3,1); 00132 lcd.printf(" "); 00133 lcd.locate(3,1); 00134 lcd.printf("%d", ki); 00135 } 00136 } 00137 if (p==4) 00138 { 00139 if (kd==0) // no mostrar nada 00140 { 00141 } 00142 else 00143 { 00144 --kd; 00145 lcd.locate(11,1); 00146 lcd.printf(" "); 00147 lcd.locate(11,1); 00148 lcd.printf("%d", kd); 00149 } 00150 } 00151 } 00152 if (button3.falling()) 00153 { 00154 00155 Sonido.write(0.5); 00156 wait(0.1); 00157 Sonido.write(0); 00158 led3 =!led3; 00159 if (p==1) 00160 { 00161 ++p; 00162 lcd.locate(11,0); 00163 lcd.printf("%d", kp); 00164 00165 00166 } 00167 else if (p==2) 00168 { 00169 ++p; 00170 lcd.locate(3,1); 00171 lcd.printf("%d", ki); 00172 lcd.locate(3,1); 00173 00174 } 00175 else if (p==3) 00176 { 00177 ++p; 00178 lcd.locate(11,1); 00179 lcd.printf("%d", kd); 00180 00181 00182 } 00183 else if (p==4) 00184 { 00185 p=1; 00186 lcd.locate(3,0); 00187 lcd.printf("%d", sp); 00188 00189 00190 } 00191 } 00192 } 00193 }
Generated on Sun Jul 24 2022 18:56:05 by
