En este programa se agrego la funcionalidad de incremento y decremento por gradiente a los botones también se creo una rutina para el anti-rebote de los botones sin usar librería

Files at this revision

API Documentation at this revision

Comitter:
amarincan
Date:
Wed Oct 16 16:52:40 2013 +0000
Commit message:
En este programa se agrego la funcionalidad de incremento y decremento con gradiente y se utilizo una t?cnica para eliminar el anti-rebote de los botones sin usar librer?as

Changed in this revision

TextLCD.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r c476b1e3e7a3 TextLCD.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TextLCD.lib	Wed Oct 16 16:52:40 2013 +0000
@@ -0,0 +1,1 @@
+https://mbed.org/users/simon/code/TextLCD/#44f34c09bd37
diff -r 000000000000 -r c476b1e3e7a3 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Oct 16 16:52:40 2013 +0000
@@ -0,0 +1,355 @@
+#include "mbed.h"
+#include "TextLCD.h"
+
+TextLCD lcd(PTB10, PTB11, PTE2, PTE3, PTE4, PTE5); // rs, e, d4-d7
+int i,Sp=0,Kp,Ki,Kd,j;
+DigitalOut l1(LED1);
+DigitalOut l2(LED2);
+int main()
+{
+
+    DigitalIn button1(PTC12);
+    DigitalIn button2(PTC13);
+    DigitalIn button3(PTC16);
+    lcd.writeCommand(0x0E);
+    lcd.printf("Sp=     Kp=");
+    lcd.locate(0,1);
+    lcd.printf("Ki=     Kd=");
+    lcd.locate(2,0);
+    lcd.printf("=");
+
+    while(1) {
+
+        if (!button1) {
+            switch(i) {
+                case 0:
+                    wait(0.5);
+                    j++;                                 // <-----ANTIREBOTE AQUI!!!
+                    while(!button1) {
+                        if((j>=1) &&(j<6)) {
+                            j++;
+                            Sp+=1;
+                        }
+                        if((j>=6)&&(j<11)&&(Sp<9999)) {
+                            j++;
+                            Sp+=10;
+                        }
+                        if((j>=11)&&(j<16)&&(Sp<9999)) {
+                            j++;
+                            Sp+=100;
+                        }
+                        if((j>=16)&&(Sp<9999)) {
+                            j++;
+                            Sp+=500;
+                        }
+                        if(Sp>9999)
+                            Sp=9999;
+                        lcd.locate(2,0);
+                        lcd.printf("=     ");
+                        lcd.locate(3,0);
+                        lcd.printf("%d",Sp);
+                        wait(1);
+                    }
+                    if(j==1)
+                        ++Sp;
+                    if(Sp>9999)
+                        Sp=9999;
+                    lcd.locate(2,0);
+                    lcd.printf("=     ");
+                    lcd.locate(3,0);
+                    lcd.printf("%d",Sp);
+                    break;
+                case 1:
+                    wait(0.5);
+                    j++;                                 // <-----ANTIREBOTE AQUI!!!
+                    while(!button1) {
+                        if((j>=1) &&(j<6)) {
+                            j++;
+                            Kp+=1;
+                        }
+                        if((j>=6)&&(j<11)&&(Kp<9999)) {
+                            j++;
+                            Kp+=10;
+                        }
+                        if((j>=11)&&(j<16)&&(Kp<9999)) {
+                            j++;
+                            Kp+=100;
+                        }
+                        if((j>=16)&&(Kp<9999)) {
+                            j++;
+                            Kp+=500;
+                        }
+                        if(Kp>9999)
+                            Kp=9999;
+                        lcd.locate(10,0);
+                        lcd.printf("=     ");
+                        lcd.locate(11,0);
+                        lcd.printf("%d",Kp);
+                        wait(1);
+                    }
+                    if(j==1)
+                        ++Kp;
+                    if(Kp>9999)
+                        Kp=9999;
+                    lcd.locate(10,0);
+                    lcd.printf("=     ");
+                    lcd.locate(11,0);
+                    lcd.printf("%d",Kp);
+                    break;
+                case 2:
+                    wait(0.5);
+                    j++;                                 // <-----ANTIREBOTE AQUI!!!
+                    while(!button1) {
+                        if((j>=1) &&(j<6)) {
+                            j++;
+                            Ki+=1;
+                        }
+                        if((j>=6)&&(j<11)&&(Ki<9999)) {
+                            j++;
+                            Ki+=10;
+                        }
+                        if((j>=11)&&(j<16)&&(Ki<9999)) {
+                            j++;
+                            Ki+=100;
+                        }
+                        if((j>=16)&&(Ki<9999)) {
+                            j++;
+                            Ki+=500;
+                        }
+                        if(Ki>9999)
+                            Ki=9999;
+                        lcd.locate(2,1);
+                        lcd.printf("=     ");
+                        lcd.locate(3,1);
+                        lcd.printf("%d",Ki);
+                        wait(1);
+                    }
+                    if(j==1)
+                        ++Ki;
+                    if(Ki>9999)
+                        Ki=9999;
+                    lcd.locate(2,1);
+                    lcd.printf("=     ");
+                    lcd.locate(3,1);
+                    lcd.printf("%d",Ki);
+                    break;
+                case 3:
+                    wait(0.5);
+                    j++;                                 // <-----ANTIREBOTE AQUI!!!
+                    while(!button1) {
+                        if((j>=1) &&(j<6)) {
+                            j++;
+                            Kd+=1;
+                        }
+                        if((j>=6)&&(j<11)&&(Kd<9999)) {
+                            j++;
+                            Kd+=10;
+                        }
+                        if((j>=11)&&(j<16)&&(Kd<9999)) {
+                            j++;
+                            Kd+=100;
+                        }
+                        if((j>=16)&&(Kd<9999)) {
+                            j++;
+                            Kd+=500;
+                        }
+                        if(Kd>9999)
+                            Kd=9999;
+                        lcd.locate(10,1);
+                        lcd.printf("=     ");
+                        lcd.locate(11,1);
+                        lcd.printf("%d",Kd);
+                        wait(1);
+                    }
+                    if(j==1)
+                        ++Kd;
+                    if(Kd>9999)
+                        Kd=9999;
+                    lcd.locate(10,1);
+                    lcd.printf("=     ");
+                    lcd.locate(11,1);
+                    lcd.printf("%d",Kd);
+                    break;
+            }
+        }
+        j=0;
+        if (!button2) {
+            switch(i) {
+                case 0:
+                    wait(0.5);
+                    j++;                                 // <-----ANTIREBOTE AQUI!!!
+                    while(!button2) {
+                        if((j>=1) &&(j<6)) {
+                            j++;
+                            Sp-=1;
+                        }
+                        if((j>=6)&&(j<11)&&(Sp>0)) {
+                            j++;
+                            Sp-=10;
+                        }
+                        if((j>=11)&&(j<16)&&(Sp>0)) {
+                            j++;
+                            Sp-=100;
+                        }
+                        if((j>=16)&&(Sp>0)) {
+                            j++;
+                            Sp-=500;
+                        }
+                        if(Sp<0)
+                            Sp=0;
+                        lcd.locate(2,0);
+                        lcd.printf("=     ");
+                        lcd.locate(3,0);
+                        lcd.printf("%d",Sp);
+                        wait(1);
+                    }
+                    if(j==1)
+                        --Sp;
+                    if(Sp<0)
+                        Sp=0;
+                    lcd.locate(2,0);
+                    lcd.printf("=     ");
+                    lcd.locate(3,0);
+                    lcd.printf("%d",Sp);
+                    break;
+                case 1:
+                    wait(0.5);
+                    j++;                                 // <-----ANTIREBOTE AQUI!!!
+                    while(!button2) {
+                        if((j>=1) &&(j<6)) {
+                            j++;
+                            Kp-=1;
+                        }
+                        if((j>=6)&&(j<11)&&(Kp>0)) {
+                            j++;
+                            Kp-=10;
+                        }
+                        if((j>=11)&&(j<16)&&(Kp>0)) {
+                            j++;
+                            Kp-=100;
+                        }
+                        if((j>=16)&&(Kp>0)) {
+                            j++;
+                            Kp-=500;
+                        }
+                        if(Kp<0)
+                            Kp=0;
+                        lcd.locate(10,0);
+                        lcd.printf("=     ");
+                        lcd.locate(11,0);
+                        lcd.printf("%d",Kp);
+                        wait(1);
+                    }
+                    if(j==1)
+                        --Kp;
+                    if(Kp<0)
+                        Kp=0;
+                    lcd.locate(10,0);
+                    lcd.printf("=     ");
+                    lcd.locate(11,0);
+                    lcd.printf("%d",Kp);
+                    break;
+                case 2:
+                    wait(0.5);
+                    j++;                                 // <-----ANTIREBOTE AQUI!!!
+                    while(!button2) {
+                        if((j>=1) &&(j<6)) {
+                            j++;
+                            Ki-=1;
+                        }
+                        if((j>=6)&&(j<11)&&(Ki>0)) {
+                            j++;
+                            Ki-=10;
+                        }
+                        if((j>=11)&&(j<16)&&(Ki>0)) {
+                            j++;
+                            Ki-=100;
+                        }
+                        if((j>=16)&&(Ki>0)) {
+                            j++;
+                            Ki-=500;
+                        }
+                        if(Ki<0)
+                            Ki=0;
+                        lcd.locate(2,1);
+                        lcd.printf("=     ");
+                        lcd.locate(3,1);
+                        lcd.printf("%d",Ki);
+                        wait(1);
+                    }
+                    if(j==1)
+                        --Ki;
+                    if(Ki<0)
+                        Ki=0;
+                    lcd.locate(2,1);
+                    lcd.printf("=     ");
+                    lcd.locate(3,1);
+                    lcd.printf("%d",Ki);
+                    break;
+                case 3:
+                    wait(0.5);
+                    j++;                                 // <-----ANTIREBOTE AQUI!!!
+                    while(!button1) {
+                        if((j>=1) &&(j<6)) {
+                            j++;
+                            Kd-=1;
+                        }
+                        if((j>=6)&&(j<11)&&(Kd>0)) {
+                            j++;
+                            Kd-=10;
+                        }
+                        if((j>=11)&&(j<16)&&(Kd>0)) {
+                            j++;
+                            Kd-=100;
+                        }
+                        if((j>=16)&&(Kd>0)) {
+                            j++;
+                            Kd-=500;
+                        }
+                        if(Kd>0)
+                            Kd=0;
+                        lcd.locate(10,1);
+                        lcd.printf("=     ");
+                        lcd.locate(11,1);
+                        lcd.printf("%d",Kd);
+                        wait(1);
+                    }
+                    if(j==1)
+                        ++Kd;
+                    if(Kd>0)
+                        Kd=0;
+                    lcd.locate(10,1);
+                    lcd.printf("=     ");
+                    lcd.locate(11,1);
+                    lcd.printf("%d",Kd);
+                    break;
+            }
+        }
+        j=0;
+        if(!button3) {
+            wait(0.5);                  // <-----ANTIREBOTE AQUI!!!
+            while(!button1);
+            i++;
+            if(i>3)
+                i=0;
+            switch (i) {
+                case 0:
+                    lcd.locate(2,0);
+                    lcd.printf("=");
+                    break;
+                case 1:
+                    lcd.locate(10,0);
+                    lcd.printf("=");
+                    break;
+                case 2:
+                    lcd.locate(2,1);
+                    lcd.printf("=");
+                    break;
+                case 3:
+                    lcd.locate(10,1);
+                    lcd.printf("=");
+                    break;
+            }
+        }
+    }
+}
\ No newline at end of file
diff -r 000000000000 -r c476b1e3e7a3 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed Oct 16 16:52:40 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/a9913a65894f
\ No newline at end of file