C&F

Dependencies:   Debounced TextLCD1 mbed

Revision:
1:ac004087d490
Parent:
0:623b3e042994
--- a/main.cpp	Tue Oct 22 01:16:39 2013 +0000
+++ b/main.cpp	Thu Oct 24 23:49:23 2013 +0000
@@ -21,7 +21,7 @@
 
 int i;                                                      // Indice de la variable.
 int j;                                                      // Controla cambio de posición.
-int kp, ki, kd, sp; 
+int kp, ki, kd, sp, cont; 
 
 int main(){
     lcd.writeCommand(C1);                                   // Escribimos un comando segun el manual del modulo LCD
@@ -45,48 +45,148 @@
            if (j==0){
                lcd.locate(3,0);
                lcd.printf("%d",sp);
-               
-               wait(0.3);
+                              
+               wait(0.2);
                   
-                  led1 = 1;
-                  if (button1.falling()) { 
-                  led1 =!led1;                            // Prendo el LED color azul cada vez que pulso el boton 1 ya que pasa a valer 0 (encendido).        
-                  ++sp;                                   // Incrementa valor al pulsar el botón.
-                                         }
-                                         
-                                         
-if (!button1) { //primer if button1 j=0 
-wait(0.3); 
-    while(sp<20){ 
-    sp=sp+1; 
-    lcd.locate(0,0); 
-    lcd.printf("Sp %d",sp); 
+               led1 = 1;
+               
+               if(button1.falling()) { 
+               led1 =!led1;                            // Prendo el LED color azul cada vez que pulso el boton 1 ya que pasa a valer 0 (encendido).        
+               //++sp;                                 // Incrementa valor al pulsar el botón --> Ahora no lo usamos acá ya que necesitamos incremental.
+               
+               
+               // Ahora comienza el incremental.               
+               
+                  if (!button1) {  
+                  cont=0;
+                  wait(0.2);
+               
+                     while(cont<20){ 
+                     cont = cont + 1;   
+                     sp=sp+1; 
+                     if (sp>1000){                     // Ponemos un tope incremental en 10.000
+                     sp=1000;
+                               }       
+                     lcd.locate(0,0); 
+                     lcd.printf("Sp %d",sp); 
+                     
+                     wait(0.3); 
+                     if(button1){ 
+                     break; 
+                                }              
+                     while(cont>=20){ 
+                     cont=cont+1;   
+                     sp=sp+10;
+                     if (sp>1000){                     // Ponemos un tope incremental en 10.000
+                     sp=1000;
+                               }  
+                     lcd.locate(0,0); 
+                     lcd.printf("Sp %d",sp); 
+                                     
+                     wait(0.3); 
+                     if(button1){ 
+                     break; 
+                                }
+                                
+                     while(cont>40){ 
+                     cont = cont + 1;   
+                     sp=sp+100;
+                     if (sp>1000){                     // Ponemos un tope incremental en 10.000
+                     sp=1000;
+                               }  
+                     lcd.locate(0,0); 
+                     lcd.printf("Sp %d",sp); 
+                     
+                     wait(0.3); 
+                     if(button1){ 
+                     break; 
+                                }                                
+                            }    
+                            }
+                            }
+                            }
+                            
+        // Aqui termina el incremental.
+                                      }
 
-wait(0.3); 
-if(button1){ 
-break; 
-} 
-}
-}
-                                         
-                                         
-                                         
-                                         
                                          
                   led2 =1;
                   if (button2.falling()) {  
-                  lcd.locate(3,0);
-                  lcd.printf("%d   ");
                   led2 =!led2;                            // Prendo el LED color rojo cada vez que pulso el boton 2 ya que pasa a valer 0 (encendido).       
-                  --sp;                                   // Reduce el valor al pulsar el botón.
+                  
+                  //--sp;                                   // Reduce el valor al pulsar el botón.
                                          } 
-                  if (sp>10000){                     // Ponemos un tope incremental en 10.000
-                  sp=10000;
-                               } 
-                                         
-                  if (sp<0){                         // No permitimos valores negativos, definimos valor mínimo en 0.
-                  sp=0;
-                           }   
+                  
+                                  
+                  // Ahora comienza el decremental.               
+               
+                  if (!button2) {  
+                  cont=0;
+                  wait(0.2);
+               
+                     while(cont<20){ 
+                     cont = cont + 1;   
+                     sp=sp-1; 
+                     
+                     lcd.locate(3,0);
+                     lcd.printf("         ");
+                     lcd.locate(0,0);
+                     lcd.printf("Sp %d",sp);
+                     
+                     if (sp<0){                         // No permitimos valores negativos, definimos valor mínimo en 0.
+                     sp=0;
+                              }
+                                          
+                                                               
+                     wait(0.3); 
+                     if(button2){ 
+                     break; 
+                                }              
+                      
+                     while(cont>=20){ 
+                     cont=cont+1;   
+                     sp=sp-10; 
+                     if (sp<0){                         // No permitimos valores negativos, definimos valor mínimo en 0.
+                     sp=0;
+                                                   }
+                     
+                     lcd.locate(0,0); 
+                     lcd.printf("Sp %d ",sp); 
+                     
+                                     
+                     wait(0.3); 
+                     if(button2){ 
+                     break; 
+                                }
+                                
+                     while(cont>40){ 
+                     cont = cont + 1;   
+                     sp=sp-100; 
+                     
+                     if (sp<0){                         // No permitimos valores negativos, definimos valor mínimo en 0.
+                     sp=0;
+                              }
+                     
+                     lcd.locate(0,0); 
+                     lcd.printf("Sp %d ",sp); 
+                     
+                     
+                     wait(0.3); 
+                     if(button2){ 
+                     break; 
+                                }                                
+                            }    
+                            }
+                            }
+                            }
+                            
+        // Aqui termina el decremental.
+                  
+                  
+                  
+                  
+                  
+                  
                            
                     }
            if (j==1){