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
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(PTC6); 00012 DebouncedIn button2(PTC10); 00013 DebouncedIn button3(PTC11); 00014 PwmOut Pwm(PTD6); 00015 00016 00017 00018 00019 //int C1=0x0F; 00020 int sp=0,kp=0,kd=0,ki=0,p=1; 00021 float periodo=0.01; 00022 int main() 00023 { 00024 Pwm.period(periodo); //Establezco el periodo para el PWM 00025 00026 lcd.cls(); 00027 //lcd.writeCommand(C1);//escribimos un comando segun el manual del modulo LCD 00028 lcd.locate(8,0); 00029 lcd.printf("kp=%d", kp); 00030 lcd.locate(0,1); 00031 lcd.printf("Ki=%d", ki); 00032 lcd.locate(8,1); 00033 lcd.printf("Kd=%d", kd); 00034 lcd.locate(0,0); 00035 lcd.printf("Sp=%d", sp); 00036 00037 while(1) 00038 { 00039 if (button1.falling()) 00040 { 00041 // Genero el PWM haciendo esperar cada que se oprime un boton 00042 Pwm.write(0.3); 00043 wait(0.03); 00044 Pwm.write(0); 00045 wait(0.03); 00046 led1 =!led1; 00047 if (p==1) 00048 { 00049 ++sp; 00050 lcd.locate(3,0); 00051 lcd.printf(" "); 00052 lcd.locate(3,0); 00053 lcd.printf("%d", sp); 00054 } 00055 else if (p==2) 00056 { 00057 ++kp; 00058 lcd.locate(11,0); 00059 lcd.printf(" "); 00060 lcd.locate(11,0); 00061 lcd.printf("%d", kp); 00062 } 00063 else if (p==3) 00064 { 00065 ++ki; 00066 lcd.locate(3,1); 00067 lcd.printf(" "); 00068 lcd.locate(3,1); 00069 lcd.printf("%d", ki); 00070 } 00071 else if (p==4) 00072 { 00073 ++kd; 00074 lcd.locate(11,1); 00075 lcd.printf(" "); 00076 lcd.locate(11,1); 00077 lcd.printf("%d", kd); 00078 } 00079 } 00080 if (button2.falling()) 00081 { 00082 // Genero el PWM haciendo esperar cada que se oprime un boton 00083 Pwm.write(0.3); 00084 wait(0.03); 00085 Pwm.write(0); 00086 wait(0.03); 00087 led2 =!led2; 00088 if (p==1) 00089 { 00090 if (sp==0) // no mostrar nada 00091 { 00092 } 00093 else 00094 { 00095 --sp; 00096 lcd.locate(3,0); 00097 lcd.printf(" "); 00098 lcd.locate(3,0); 00099 lcd.printf("%d", sp); 00100 } 00101 } 00102 if (p==2) 00103 { 00104 if (kp==0) // no mostrar nada 00105 { 00106 } 00107 else 00108 { 00109 --kp; 00110 lcd.locate(11,0); 00111 lcd.printf(" "); 00112 lcd.locate(11,0); 00113 lcd.printf("%d", kp); 00114 } 00115 } 00116 if (p==3) 00117 { 00118 if (ki==0) // no mostrar nada 00119 { 00120 } 00121 else 00122 { 00123 --ki; 00124 lcd.locate(3,1); 00125 lcd.printf(" "); 00126 lcd.locate(3,1); 00127 lcd.printf("%d", ki); 00128 } 00129 } 00130 if (p==4) 00131 { 00132 if (kd==0) // no mostrar nada 00133 { 00134 } 00135 else 00136 { 00137 --kd; 00138 lcd.locate(11,1); 00139 lcd.printf(" "); 00140 lcd.locate(11,1); 00141 lcd.printf("%d", kd); 00142 } 00143 } 00144 } 00145 if (button3.falling()) 00146 { 00147 // Genero el PWM haciendo esperar cada que se oprime un boton 00148 Pwm.write(0.3); 00149 wait(0.03); 00150 Pwm.write(0); 00151 wait(0.03); 00152 led3 =!led3; 00153 if (p==1) 00154 { 00155 ++p; 00156 lcd.locate(11,0); 00157 lcd.printf("%d", kp); 00158 00159 00160 } 00161 else if (p==2) 00162 { 00163 ++p; 00164 lcd.locate(3,1); 00165 lcd.printf("%d", ki); 00166 lcd.locate(3,1); 00167 00168 } 00169 else if (p==3) 00170 { 00171 ++p; 00172 lcd.locate(11,1); 00173 lcd.printf("%d", kd); 00174 00175 00176 } 00177 else if (p==4) 00178 { 00179 p=1; 00180 lcd.locate(3,0); 00181 lcd.printf("%d", sp); 00182 00183 00184 } 00185 } 00186 } 00187 }
Generated on Mon Aug 1 2022 02:17:06 by
1.7.2