Tarea1

Dependencies:   Debounced TextLCD1 mbed

Files at this revision

API Documentation at this revision

Comitter:
lcorralesc1
Date:
Sun Oct 20 07:22:30 2013 +0000
Commit message:
Tarea1 con incremental final

Changed in this revision

Debounced.lib Show annotated file Show diff for this revision Revisions of this file
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 964cee3e89ee Debounced.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Debounced.lib	Sun Oct 20 07:22:30 2013 +0000
@@ -0,0 +1,1 @@
+https://mbed.org/users/WarwickRacing/code/Debounced/#8992c13bbb9b
diff -r 000000000000 -r 964cee3e89ee TextLCD.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TextLCD.lib	Sun Oct 20 07:22:30 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/lcorralesc1/code/TextLCD1/#d7956bcc25ff
diff -r 000000000000 -r 964cee3e89ee main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sun Oct 20 07:22:30 2013 +0000
@@ -0,0 +1,770 @@
+#include "mbed.h"
+#include "DebouncedIn.h"
+#include "TextLCD.h"
+
+AnalogIn Vin(PTC2);
+TextLCD lcd(PTB10, PTB11, PTE2, PTE3, PTE4, PTE5); // rs, e, d4-d7
+
+DigitalOut led1(LED1);
+DigitalOut led2(LED2);
+DigitalOut led3(LED3);
+DigitalIn button1(PTC12);
+DigitalIn button2(PTC13);
+DigitalIn button3(PTC16);
+//DigitalIn button4(PTC17);
+
+//DebouncedIn button1(PTC12);
+//DebouncedIn button2(PTC13);
+//DebouncedIn button3(PTC16);
+//DebouncedIn button4(PTC17);
+
+      //codigos movimiento del curzor
+      //18 para izquierda
+      //1A para derecha
+
+int C1=0x0E; // solo muestra el curzor
+int C2=0x18; // desplaza izquierda
+int C3=0x1A; // desplaza derecha
+int C4=0x0C; // quito cursor bajo
+
+int contador1, contador2, contador3, contador4; // variable con la que controlo disminucion de conteo
+int j=0; //variable controla cambio 4 posiciones
+int kp, ki, kd, sp, i; 
+
+int main() {
+    lcd.writeCommand(C1);//escribimos un comando segun el manual del modulo LCD
+    lcd.cls();
+    lcd.locate(0,0);
+    lcd.printf("Sp%d",sp);//primero print y luego locate
+    lcd.locate(8,0);
+    lcd.printf("Kp%d",kp);
+    lcd.locate(0,1);
+    lcd.printf("Ki%d",ki);
+    lcd.locate(8,1);
+    lcd.printf("Kd%d",kd);
+
+while(1) {
+
+   if(!button3){
+     j=j+1;
+    
+     lcd.locate(2,0);
+     lcd.writeCommand(C1);
+       if(button3){
+       break;
+                  }
+               }      
+
+                                                                
+           while (j==0){
+              
+               wait(0.3);
+               
+                  if (!button1) {                                //primer if button1 j=0
+                    wait(0.3); 
+                    while(sp<5){
+                    sp=sp+1;
+                    lcd.locate(0,0);
+                    lcd.printf("Sp%d ",sp);
+                    wait(0.3);
+                    
+                      if(button1){
+                      break;
+                                 }       
+                                }                      
+                    wait(0.3);   
+                    
+                       if(!button1){                             //segundo if button1 j=0
+                          wait(0.3);
+                          while(sp<50){
+                          sp=sp+5;
+                          lcd.locate(0,0);
+                          lcd.printf("Sp%d ",sp);
+                          wait(0.3);
+                            if(button1){
+                            break;
+                                       }   
+                                      }
+                          wait(0.3);
+                             
+                             if(!button1){                       //tercer if button1 j=0
+                                wait(0.3);
+                                while(sp<100){
+                                sp=sp+10;
+                                lcd.locate(0,0);
+                                lcd.printf("Sp%d ",sp);
+                                wait(0.3);
+                                  if(button1){
+                                  break;
+                                             }
+                                             }           
+                                wait(0.3);
+                                
+                                  if(!button1){                  //cuarto if button1 j=0
+                                    wait(0.3);
+                                    while(sp<1000){
+                                    sp=sp+100;
+                                    lcd.locate(0,0);
+                                    lcd.printf("Sp%d ",sp);
+                                    wait(0.3);
+                                      if(button1){
+                                      break;
+                                                 } 
+                                                 }
+                                    wait(0.3);
+                                    
+                                      if(!button1){              //quinto if button1 j=0
+                                        wait(0.3);
+                                        while(sp<10000){
+                                        sp=sp+1000;
+                                        lcd.locate(0,0);
+                                        lcd.printf("Sp%d ",sp);
+                                        wait(0.3);
+                                          if(button1){
+                                          break;
+                                                      }
+                                                      }
+                                                      
+                                                      
+                                                      
+                                                     
+                                                  }        //cierro quinto if button1 j=0        
+                                                 
+                                                 
+                                                 
+                                              }           //cierro cuarto if button1 j=0
+                                               
+                                             
+                                         }                //cierro tercer if button1 j=0
+                       
+                                   }                      //cierro segundo if button1 j=0
+                  
+                   
+                   
+               
+                               }                          //cierro primer if button1 j=0
+                               
+             
+                               
+                        
+                    if(!button2){
+                         wait(0.2);
+                         
+                         while(contador1<10 & sp>0){
+                         contador1=contador1+1;
+                           sp=sp-1;
+                             if(sp<0){
+                             sp=0;
+                                     }
+                           lcd.locate(0,0);
+                           lcd.printf("Sp%d ",sp);
+                           //lcd.locate(12,0);
+                           //lcd.printf("C%d",contador1);
+                           wait(0.3);  
+                           
+                             if(button2){
+                               break;
+                                        }     
+                                               }
+                           wait(0.3);
+                             
+                             if(!button2){
+                               wait(0.2);
+                               while(contador1>=10 & contador1<19){
+                                 contador1=contador1+1;
+                                 sp=sp-10;
+                                   if(sp<0){
+                                   sp=0;
+                                           }
+                                 lcd.locate(0,0);
+                                 lcd.printf("Sp%d ",sp);
+                                 //lcd.locate(12,0);
+                                 //lcd.printf("C%d",contador1);
+                                 wait(0.3);
+                                 
+                                   if(button2){
+                                     break;
+                                              }
+                                                   }
+                                 wait(0.3);
+                                 
+                                   if(!button2){
+                                     wait(0.2);
+                                     while(contador1>=19){
+                                       contador1=contador1+1;
+                                       sp=sp-100;
+                                         if(sp<0){
+                                         sp=0;
+                                                 }
+                                       lcd.locate(0,0);
+                                       lcd.printf("Sp%d ",sp);
+                                       //lcd.locate(12,0);
+                                       //lcd.printf("C%d",contador1);
+                                       wait(0.3);
+                                         
+                                         if(button2){
+                                         break;
+                                                    }          
+                                                          }
+                                                          
+                                               }          //cierro tercer if button2 j=0        
+                                                   
+                               
+                               
+                                         }                //cierro segundo if button2 j=0           
+                                               
+                                               
+                                }                         //cierro primer if button2 j=0  
+                                
+  if(!button3){
+    j=j+1;
+     
+    lcd.locate(10,0);
+    lcd.writeCommand(C1);
+    if(button3){
+       break;
+               }
+              }                                           
+                               
+                        }                                 //cierro while con j=0
+                        
+                         
+//%------------------------------------------------------------------------------------------                     
+
+                        
+                        
+                        
+while (j==1){
+              
+               wait(0.3);
+               
+                  if (!button1) {                                //primer if button1 j=1 
+                    wait(0.2); 
+                    while(kp<5){
+                    kp=kp+1;
+                    lcd.locate(8,0);
+                    lcd.printf("Kp%d ",kp);
+                    wait(0.4);
+                      if(button1){
+                      break;
+                                 }
+                                }                      
+                    wait(0.4);   
+                    
+                       if(!button1){                             //segundo if button1 j=1 
+                          wait(0.3);
+                          while(kp<50){
+                          kp=kp+5;
+                          lcd.locate(8,0);
+                          lcd.printf("Kp%d ",kp);
+                          wait(0.4);
+                            if(button1){
+                            break;
+                                       }   
+                                      }
+                          wait(0.4);
+                             
+                             if(!button1){                       //tercer if button1 j=1 
+                                wait(0.3);
+                                while(kp<100){
+                                kp=kp+10;
+                                lcd.locate(8,0);
+                                lcd.printf("Kp%d ",kp);
+                                wait(0.4);
+                                  if(button1){
+                                  break;
+                                             }
+                                             }           
+                                wait(0.4);
+                                
+                                  if(!button1){                  //cuarto if button1 j=1 
+                                    wait(0.3);
+                                    while(kp<1000){
+                                    kp=kp+100;
+                                    lcd.locate(8,0);
+                                    lcd.printf("Kp%d ",kp);
+                                    wait(0.4);
+                                      if(button1){
+                                      break;
+                                                 } 
+                                                 }
+                                    wait(0.4);
+                                    
+                                      if(!button1){              //quinto if button1 j=1 
+                                        wait(0.3);
+                                        while(kp<10000){
+                                        kp=kp+1000;
+                                        lcd.locate(8,0);
+                                        lcd.printf("Kp%d ",kp);
+                                        wait(0.4);
+                                          if(button1){
+                                          break;
+                                                      }
+                                                      }
+                                                      
+                                                      
+                                                      
+                                                     
+                                                  }        //cierro quinto if button1 j=1        
+                                                 
+                                                 
+                                                 
+                                              }           //cierro cuarto if button1 j=1
+                                               
+                                             
+                                         }                //cierro tercer if button1 j=1
+                       
+                                   }                      //cierro segundo if button1 j=1
+                  
+                   
+                   
+               
+                               }                          //cierro primer if button1 j=1
+                               
+                               
+                               
+                               
+                    if(!button2){
+                         wait(0.2);
+                         
+                         while(contador2<10 & kp>0){
+                         contador2=contador2+1;
+                           kp=kp-1;
+                             if(kp<0){
+                             kp=0;
+                                     }
+                           lcd.locate(8,0);
+                           lcd.printf("Kp%d ",kp);
+                           //lcd.locate(12,1);
+                           //lcd.printf("C%d",contador2);
+                           wait(0.3);  
+                           
+                             if(button2){
+                               break;
+                                        }     
+                                               }
+                           wait(0.3);
+                             
+                             if(!button2){
+                               wait(0.2);
+                               while(contador2>=10 & contador2<19){
+                                 contador2=contador2+1;
+                                 kp=kp-10;
+                                   if(kp<0){
+                                   kp=0;
+                                           }
+                                 lcd.locate(8,0);
+                                 lcd.printf("Kp%d ",kp);
+                                 //lcd.locate(12,1);
+                                 //lcd.printf("C%d",contador2);
+                                 wait(0.3);
+                                 
+                                   if(button2){
+                                     break;
+                                              }
+                                                   }
+                                 wait(0.3);
+                                 
+                                   if(!button2){
+                                     wait(0.2);
+                                     while(contador2>=19){
+                                       contador2=contador2+1;
+                                       kp=kp-100;
+                                         if(kp<0){
+                                         kp=0;
+                                                 }
+                                       lcd.locate(8,0);
+                                       lcd.printf("Kp%d ",kp);
+                                       //lcd.locate(12,1);
+                                       //lcd.printf("C%d",contador2);
+                                       wait(0.3);
+                                         
+                                         if(button2){
+                                         break;
+                                                    }          
+                                                          }
+                                                          
+                                               }          //cierro tercer if button2 j=1        
+                                                   
+                               
+                               
+                                         }                //cierro segundo if button2 j=1           
+                                               
+                                               
+                                }                         //cierro primer if button2 j=1             
+                               
+   if(!button3){
+    j=j+1;
+    
+    lcd.locate(0,2);
+    lcd.writeCommand(C1);
+    if(button3){
+       break;
+               }
+              } 
+                               
+                        }                                 //cierro while con j=1
+                        
+                        
+                        
+//%----------------------------------------------------------------------------------------------                        
+
+
+
+while (j==2){
+              
+               wait(0.3);
+               
+                  if (!button1) {                                //primer if button1 j=2 
+                    wait(0.2); 
+                    while(ki<5){
+                    ki=ki+1;
+                    lcd.locate(0,1);
+                    lcd.printf("Ki%d ",ki);
+                    wait(0.4);
+                      if(button1){
+                      break;
+                                 }
+                                }                      
+                    wait(0.4);   
+                    
+                       if(!button1){                             //segundo if button1 j=2 
+                          wait(0.3);
+                          while(ki<50){
+                          ki=ki+5;
+                          lcd.locate(0,1);
+                          lcd.printf("Ki%d ",ki);
+                          wait(0.4);
+                            if(button1){
+                            break;
+                                       }   
+                                      }
+                          wait(0.4);
+                             
+                             if(!button1){                       //tercer if button1 j=2 
+                                wait(0.3);
+                                while(ki<100){
+                                ki=ki+10;
+                                lcd.locate(0,1);
+                                lcd.printf("Ki%d ",ki);
+                                wait(0.4);
+                                  if(button1){
+                                  break;
+                                             }
+                                             }           
+                                wait(0.4);
+                                
+                                  if(!button1){                  //cuarto if button1 j=2 
+                                    wait(0.3);
+                                    while(ki<1000){
+                                    ki=ki+100;
+                                    lcd.locate(0,1);
+                                    lcd.printf("Ki%d ",ki);
+                                    wait(0.4);
+                                      if(button1){
+                                      break;
+                                                 } 
+                                                 }
+                                    wait(0.4);
+                                    
+                                      if(!button1){              //quinto if button1 j=2
+                                        wait(0.3);
+                                        while(ki<10000){
+                                        ki=ki+1000;
+                                        lcd.locate(0,1);
+                                        lcd.printf("Ki%d ",ki);
+                                        wait(0.4);
+                                          if(button1){
+                                          break;
+                                                      }
+                                                      }
+                                                      
+                                                      
+                                                      
+                                                     
+                                                  }        //cierro quinto if button1 j=2        
+                                                 
+                                                 
+                                                 
+                                              }           //cierro cuarto if button1 j=2
+                                               
+                                             
+                                         }                //cierro tercer if button1 j=2
+                       
+                                   }                      //cierro segundo if button1 j=2
+                  
+                   
+                   
+               
+                               }                          //cierro primer if button1 j=2
+                               
+                               
+                               
+                               
+                    if(!button2){
+                         wait(0.2);
+                         
+                         while(contador3<10 & ki>0){
+                         contador3=contador3+1;
+                           ki=ki-1;
+                             if(ki<0){
+                             ki=0;
+                                     }
+                           lcd.locate(0,1);
+                           lcd.printf("Ki%d ",ki);
+                           //lcd.locate(12,1);
+                           //lcd.printf("C%d",contador3);
+                           wait(0.3);  
+                           
+                             if(button2){
+                               break;
+                                        }     
+                                               }
+                           wait(0.3);
+                             
+                             if(!button2){
+                               wait(0.2);
+                               while(contador3>=10 & contador3<19){
+                                 contador3=contador3+1;
+                                 ki=ki-10;
+                                   if(ki<0){
+                                   ki=0;
+                                           }
+                                 lcd.locate(0,1);
+                                 lcd.printf("Ki%d ",ki);
+                                 //lcd.locate(12,1);
+                                 //lcd.printf("C%d",contador3);
+                                 wait(0.3);
+                                 
+                                   if(button2){
+                                     break;
+                                              }
+                                                   }
+                                 wait(0.3);
+                                 
+                                   if(!button2){
+                                     wait(0.2);
+                                     while(contador3>=19){
+                                       contador3=contador3+1;
+                                       ki=ki-100;
+                                         if(ki<0){
+                                         ki=0;
+                                                 }
+                                       lcd.locate(0,1);
+                                       lcd.printf("Ki%d ",ki);
+                                       //lcd.locate(12,1);
+                                       //lcd.printf("C%d",contador3);
+                                       wait(0.3);
+                                         
+                                         if(button2){
+                                         break;
+                                                    }          
+                                                          }
+                                                          
+                                               }          //cierro tercer if button2 j=2        
+                                                   
+                               
+                               
+                                         }                //cierro segundo if button2 j=2           
+                                               
+                                               
+                                }                         //cierro primer if button2 j=2               
+                               
+  if(!button3){
+    j=j+1;
+     
+    lcd.locate(10,1);
+    lcd.writeCommand(C1);
+    if(button3){
+       break;
+               }
+              }                       
+                             
+                        }                                 //cierro while con j=2
+
+                     
+           
+//%----------------------------------------------------------------------------------------------                  
+
+
+
+
+while (j==3){
+              
+               wait(0.3);
+               
+                  if (!button1) {                                //primer if button1 j=3 
+                    wait(0.2); 
+                    while(kd<5){
+                    kd=kd+1;
+                    lcd.locate(8,1);
+                    lcd.printf("Kd%d ",kd);
+                    wait(0.4);
+                      if(button1){
+                      break;
+                                 }
+                                }                      
+                    wait(0.4);   
+                    
+                       if(!button1){                             //segundo if button1 j=3 
+                          wait(0.3);
+                          while(kd<50){
+                          kd=kd+5;
+                          lcd.locate(8,1);
+                          lcd.printf("Kd%d ",kd);
+                          wait(0.4);
+                            if(button1){
+                            break;
+                                       }   
+                                      }
+                          wait(0.4);
+                             
+                             if(!button1){                       //tercer if button1 j=3
+                                wait(0.3);
+                                while(kd<100){
+                                kd=kd+10;
+                                lcd.locate(8,1);
+                                lcd.printf("Kd%d ",kd);
+                                wait(0.4);
+                                  if(button1){
+                                  break;
+                                             }
+                                             }           
+                                wait(0.4);
+                                
+                                  if(!button1){                  //cuarto if button1 j=2 
+                                    wait(0.3);
+                                    while(kd<1000){
+                                    kd=kd+100;
+                                    lcd.locate(8,1);
+                                    lcd.printf("Kd%d ",kd);
+                                    wait(0.4);
+                                      if(button1){
+                                      break;
+                                                 } 
+                                                 }
+                                    wait(0.4);
+                                    
+                                      if(!button1){              //quinto if button1 j=2
+                                        wait(0.3);
+                                        while(kd<10000){
+                                        kd=kd+1000;
+                                        lcd.locate(8,1);
+                                        lcd.printf("Kd%d ",kd);
+                                        wait(0.4);
+                                          if(button1){
+                                          break;
+                                                      }
+                                                      }
+                                                      
+                                                      
+                                                      
+                                                     
+                                                  }        //cierro quinto if button1 j=3        
+                                                 
+                                                 
+                                                 
+                                              }           //cierro cuarto if button1 j=3
+                                               
+                                             
+                                         }                //cierro tercer if button1 j=3
+                       
+                                   }                      //cierro segundo if button1 j=3
+                  
+                   
+               
+                               }                          //cierro primer if button1 j=3
+                               
+                               
+                               
+                               
+                    if(!button2){
+                         wait(0.2);
+                         
+                         while(contador4<10 & kd>0){
+                         contador4=contador4+1;
+                           kd=kd-1;
+                             if(kd<0){
+                             kd=0;
+                                     }
+                           lcd.locate(8,1);
+                           lcd.printf("Kd%d ",kd);
+                           //lcd.locate(12,0);
+                           //lcd.printf("C%d",contador4);
+                           wait(0.3);  
+                           
+                             if(button2){
+                               break;
+                                        }     
+                                               }
+                           wait(0.3);
+                             
+                             if(!button2){
+                               wait(0.2);
+                               while(contador4>=10 & contador4<19){
+                                 contador4=contador4+1;
+                                 kd=kd-10;
+                                   if(kd<0){
+                                   kd=0;
+                                           }
+                                 lcd.locate(8,1);
+                                 lcd.printf("Kd%d ",kd);
+                                 //lcd.locate(12,0);
+                                 //lcd.printf("C%d",contador4);
+                                 wait(0.3);
+                                 
+                                   if(button2){
+                                     break;
+                                              }
+                                                   }
+                                 wait(0.3);
+                                 
+                                   if(!button2){
+                                     wait(0.2);
+                                     while(contador4>=19){
+                                       contador4=contador4+1;
+                                       kd=kd-100;
+                                         if(kd<0){
+                                         kd=0;
+                                                 }
+                                       lcd.locate(8,1);
+                                       lcd.printf("Kd%d ",kd);
+                                       //lcd.locate(12,0);
+                                       //lcd.printf("C%d",contador4);
+                                       wait(0.3);
+                                         
+                                         if(button2){
+                                         break;
+                                                    }          
+                                                          }
+                                                          
+                                               }          //cierro tercer if button2 j=3       
+                                                   
+                               
+                               
+                                         }                //cierro segundo if button2 j=3           
+                                               
+                                               
+                                }                         //cierro primer if button2 j=3                
+                   
+   if(!button3){
+    j=j+1;
+     
+    lcd.locate(0,0);
+    lcd.writeCommand(C1);
+    if(button3){
+       break;
+               }
+              }                                     
+                        }                                 //cierro while con j=3
+
+
+//%----------------------------------------------------------------------------------------------
+ while(j==4){
+    j=-1;
+         } 
+                  
+          }                                               //cierro while(1)
+         
+            }                                             //cierro main
+                  
diff -r 000000000000 -r 964cee3e89ee mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sun Oct 20 07:22:30 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/a9913a65894f
\ No newline at end of file