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: QEI TextLCD mbed
main.cpp
00001 #include "mbed.h" 00002 #include "QEI.h" 00003 #include "TextLCD.h" 00004 00005 TextLCD lcd(PTB10, PTB11, PTE2, PTE3, PTE4, PTE5); // rs, e, d4-d7 00006 QEI encoder (PTD6, PTD7, PTA17, 624); 00007 AnalogIn Vin(PTB0); 00008 PwmOut sonido(PTA12); 00009 AnalogOut Vout(PTE30); 00010 DigitalIn button3(PTA17); 00011 00012 int C2=0x18; // Desplazamiento Izquierda 00013 int C3=0x1A; // Desplazamiento Derecha 00014 int C4=0x0C; // Quitar cursor bajo 00015 int C1=0x0F; 00016 int err, med, yr, pid, ap, ai, ad, err_v, cambio=0, diferencia=0; 00017 int spnum=0,kinum=0,kpnum=0,kdnum=0,pos=1; 00018 int flagt=0; 00019 float Dd=10; 00020 float pp=30; 00021 float Fi; 00022 00023 00024 int main() 00025 { 00026 lcd.cls(); // Borrar Pantalla 00027 lcd.writeCommand(C1);//escribimos un comando segun el manual del modulo LCD 00028 00029 lcd.locate(8,0); 00030 lcd.printf("Kp=%d",kpnum); 00031 lcd.locate(0,1); 00032 lcd.printf("Ki=%d",kinum); 00033 lcd.locate(8,1); 00034 lcd.printf("Kd=%d",kdnum); 00035 lcd.locate(0,0); 00036 lcd.printf("Sp=%d",spnum); 00037 00038 while(1) 00039 { diferencia=encoder.getPulses()-cambio; 00040 cambio=encoder.getPulses(); 00041 00042 if (diferencia==0) 00043 { 00044 //no hace nada 00045 } 00046 else if(diferencia>0) 00047 { 00048 if(pos==1) 00049 { 00050 if(spnum+diferencia>=999) 00051 { 00052 spnum=999; 00053 lcd.locate(3,0); 00054 lcd.printf(" "); 00055 lcd.locate(3,0); 00056 lcd.printf("%d", spnum); 00057 } 00058 else 00059 { 00060 spnum+=diferencia; 00061 lcd.locate(3,0); 00062 lcd.printf("%d", spnum); 00063 } 00064 } 00065 else if(pos==2) 00066 { 00067 if(kpnum+diferencia>=999) 00068 { 00069 kpnum=999; 00070 lcd.locate(11,0); 00071 lcd.printf(" "); 00072 lcd.locate(11,0); 00073 lcd.printf("%d", kpnum); 00074 } 00075 else 00076 { 00077 kpnum+=diferencia; 00078 lcd.locate(11,0); 00079 lcd.printf("%d", kpnum); 00080 } 00081 } 00082 else if(pos==3) 00083 { 00084 if(kinum+diferencia>=999) 00085 { 00086 kinum=999; 00087 lcd.locate(3,1); 00088 lcd.printf(" "); 00089 lcd.locate(3,1); 00090 lcd.printf("%d", kinum); 00091 } 00092 else 00093 { 00094 kinum+=diferencia; 00095 lcd.locate(3,1); 00096 lcd.printf("%d", kinum); 00097 } 00098 } 00099 else if(pos==4) 00100 { 00101 if(kdnum+diferencia>=999) 00102 { 00103 kdnum=999; 00104 lcd.locate(11,1); 00105 lcd.printf(" "); 00106 lcd.locate(11,1); 00107 lcd.printf("%d", kdnum); 00108 } 00109 else 00110 { 00111 kdnum+=diferencia; 00112 lcd.locate(11,1); 00113 lcd.printf("%d", kdnum); 00114 } 00115 } 00116 } 00117 00118 else if(diferencia<0) 00119 { 00120 if(pos==1) 00121 { 00122 if(spnum+diferencia<0) 00123 { 00124 //No hace nada 00125 } 00126 else 00127 { 00128 spnum+=diferencia; 00129 lcd.locate(3,0); 00130 lcd.printf(" "); 00131 lcd.locate(3,0); 00132 lcd.printf("%d", spnum); 00133 } 00134 } 00135 else if(pos==2) 00136 { 00137 if(kpnum+diferencia<0) 00138 { 00139 //No hace nada 00140 } 00141 else 00142 { 00143 kpnum+=diferencia; 00144 lcd.locate(11,0); 00145 lcd.printf(" "); 00146 lcd.locate(11,0); 00147 lcd.printf("%d", kpnum); 00148 } 00149 } 00150 else if(pos==3) 00151 { 00152 if(kinum+diferencia<0) 00153 { 00154 //No hace nada 00155 } 00156 else 00157 { 00158 kinum+=diferencia; 00159 lcd.locate(3,1); 00160 lcd.printf(" "); 00161 lcd.locate(3,1); 00162 lcd.printf("%d", kinum); 00163 } 00164 } 00165 else if(pos==4) 00166 { 00167 if(kdnum+diferencia<0) 00168 { 00169 //No hace nada 00170 } 00171 else 00172 { 00173 kdnum+=diferencia; 00174 lcd.locate(11,1); 00175 lcd.printf(" "); 00176 lcd.locate(11,1); 00177 lcd.printf("%d", kdnum); 00178 } 00179 } 00180 } 00181 00182 if (!button3) 00183 { Fi=(Dd)*100; 00184 pp=(1/Fi); 00185 sonido.period(pp); 00186 { 00187 00188 sonido.write(0.3);; 00189 wait(0.1); 00190 sonido=0.0; 00191 00192 } 00193 if(pos==4) 00194 { 00195 pos=1; 00196 lcd.locate(3,0); 00197 lcd.printf("%d", spnum); 00198 } 00199 else if (pos==1) 00200 { 00201 pos++; 00202 lcd.locate(11,0); 00203 lcd.printf("%d", kpnum); 00204 } 00205 else if(pos==2) 00206 { 00207 pos++; 00208 lcd.locate(3,1); 00209 lcd.printf("%d", kinum); 00210 } 00211 else if(pos==3) 00212 { 00213 pos++; 00214 lcd.locate(11,1); 00215 lcd.printf("%d", kdnum); 00216 } 00217 wait(0.25); 00218 00219 } 00220 00221 } 00222 } 00223
Generated on Sat Jul 16 2022 17:31:56 by
1.7.2