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
Diff: main.cpp
- Revision:
- 0:527c9de31b3c
diff -r 000000000000 -r 527c9de31b3c main.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Fri Oct 11 05:28:33 2013 +0000
@@ -0,0 +1,117 @@
+#include "mbed.h"
+#include "TextLCD.h"
+#include "DebounceIn.h"
+
+TextLCD lcd(PTE0,PTE1,PTE2,PTE3,PTE4,PTE5); //configura los puestos PTE0,PTE1,PTE2,PTE3,PTE4,PTE5, donde se conectara el LCD 16x2
+DebounceIn mas(PTA1);
+DebounceIn menos(PTA2);
+DebounceIn salto(PTA3);
+
+int s=0; //set point
+int p=0; //ganancia proporcional
+int i=0; //ganancia integral
+int d=0; //ganancia derivativa
+int k=1; //variable de control}
+
+void def_posicion(int h){
+ if (h==0){
+ lcd.locate(3,0);
+ }
+ else if(h==1){
+ lcd.locate(10,0);
+ }
+ else if (h==2){
+ lcd.locate(3,1);
+ }
+ else {
+ lcd.locate(10,1);
+ }
+}
+void decremento(int u){ //Funcion que decrementa los valores
+if(u==0){
+ if(s<=0){
+ s=0;
+ lcd.printf("%d",s);
+ }
+ else{
+ s--;
+ lcd.printf("%d",s);
+ }
+ }
+else if(u==1){
+ if(p<=0){
+ p=0;
+ lcd.printf("%d",p);
+ }
+ else{
+ p--;
+ lcd.printf("%d",p);
+ }
+}
+else if(u==2){
+ if(i<=0){
+ i=0;
+ lcd.printf("%d",i);
+ }
+ else{
+ i--;
+ lcd.printf("%d",i);
+ }
+ }
+else if(d<=0){
+ d=0;
+ lcd.printf("%d",d);
+ }
+else {
+ d--;
+ lcd.printf("%d",d);
+ }
+}
+
+void incremento(int h){ //Funcion que incremente los valores
+if(h==0){
+ s++;
+ lcd.printf("%d",s);
+ }
+else if(h==1){
+ p++;
+ lcd.printf("%d",p);
+ }
+else if(h==2){
+ i++;
+ lcd.printf("%d",i);
+ }
+else{
+ d++;
+ lcd.printf("%d",d);
+ }
+
+}
+
+void star_patch(void){ //funcion que imprime los caracteres que no van a variar en el display
+lcd.printf("SP=");
+lcd.locate(7,0);
+lcd.printf("Kp=");
+lcd.locate(0,1);
+lcd.printf("Ki=");
+lcd.locate(7,1);
+lcd.printf("Kd=");
+lcd.locate(3,0);
+}
+
+int main(){
+star_patch();
+while(1){
+ if(k==3)k=0;
+ if(salto.read()==0){
+ def_posicion(k);
+ k++;
+ }
+ else if(mas.read()==0){
+ incremento(k);
+ }
+ else if(menos.read()==0){
+ decremento(k);
+ }
+}
+}
\ No newline at end of file