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: DebounceIn TextLCD mbed
main.cpp
00001 #include "mbed.h" 00002 #include "TextLCD.h" 00003 #include "DebounceIn.h" 00004 00005 TextLCD lcd(PTE0,PTE1,PTE2,PTE3,PTE4,PTE5); //configura los puestos PTE0,PTE1,PTE2,PTE3,PTE4,PTE5, donde se conectara el LCD 16x2 00006 DebounceIn mas(PTA1); 00007 DebounceIn menos(PTA2); 00008 DebounceIn salto(PTA3); 00009 00010 int s=0; //set point 00011 int p=0; //ganancia proporcional 00012 int i=0; //ganancia integral 00013 int d=0; //ganancia derivativa 00014 int k=1; //variable de control} 00015 00016 void def_posicion(int h){ 00017 if (h==0){ 00018 lcd.locate(3,0); 00019 } 00020 else if(h==1){ 00021 lcd.locate(10,0); 00022 } 00023 else if (h==2){ 00024 lcd.locate(3,1); 00025 } 00026 else { 00027 lcd.locate(10,1); 00028 } 00029 } 00030 void decremento(int u){ //Funcion que decrementa los valores 00031 if(u==0){ 00032 if(s<=0){ 00033 s=0; 00034 lcd.printf("%d",s); 00035 } 00036 else{ 00037 s--; 00038 lcd.printf("%d",s); 00039 } 00040 } 00041 else if(u==1){ 00042 if(p<=0){ 00043 p=0; 00044 lcd.printf("%d",p); 00045 } 00046 else{ 00047 p--; 00048 lcd.printf("%d",p); 00049 } 00050 } 00051 else if(u==2){ 00052 if(i<=0){ 00053 i=0; 00054 lcd.printf("%d",i); 00055 } 00056 else{ 00057 i--; 00058 lcd.printf("%d",i); 00059 } 00060 } 00061 else if(d<=0){ 00062 d=0; 00063 lcd.printf("%d",d); 00064 } 00065 else { 00066 d--; 00067 lcd.printf("%d",d); 00068 } 00069 } 00070 00071 void incremento(int h){ //Funcion que incremente los valores 00072 if(h==0){ 00073 s++; 00074 lcd.printf("%d",s); 00075 } 00076 else if(h==1){ 00077 p++; 00078 lcd.printf("%d",p); 00079 } 00080 else if(h==2){ 00081 i++; 00082 lcd.printf("%d",i); 00083 } 00084 else{ 00085 d++; 00086 lcd.printf("%d",d); 00087 } 00088 00089 } 00090 00091 void star_patch(void){ //funcion que imprime los caracteres que no van a variar en el display 00092 lcd.printf("SP="); 00093 lcd.locate(7,0); 00094 lcd.printf("Kp="); 00095 lcd.locate(0,1); 00096 lcd.printf("Ki="); 00097 lcd.locate(7,1); 00098 lcd.printf("Kd="); 00099 lcd.locate(3,0); 00100 } 00101 00102 int main(){ 00103 star_patch(); 00104 while(1){ 00105 if(k==3)k=0; 00106 if(salto.read()==0){ 00107 def_posicion(k); 00108 k++; 00109 } 00110 else if(mas.read()==0){ 00111 incremento(k); 00112 } 00113 else if(menos.read()==0){ 00114 decremento(k); 00115 } 00116 } 00117 }
Generated on Thu Jul 14 2022 21:18:34 by
1.7.2