jorge arturo juarez ornelas / Mbed 2 deprecated pruebadetablero

Dependencies:   TextLCD mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 
00003 #include "TextLCD.h"
00004 
00005 Serial pc(USBTX,USBRX);
00006 //TextLCD lcd(PTB9, PTB10, PTE2, PTE3, PTE4, PTE5);
00007 TextLCD lcd(D0, D1, D2, D3, D4, D5); 
00008 
00009 
00010 
00011 DigitalIn boton1(D6);
00012 DigitalIn boton2(D7);
00013 DigitalIn boton3(D8);
00014 DigitalIn boton4(D9);
00015 DigitalIn boton6(D10);
00016 DigitalIn boton5(D11);
00017 DigitalOut alarma(D12);
00018 
00019 int horas;
00020 int minutos=0;
00021 int segundos=0;
00022 int segundos2=25;
00023 //int segundoss=0;
00024 int x=0;
00025 Timer t;
00026 
00027 Timer s;
00028 
00029 int v=0;
00030 int l=0;
00031 int p=-1;
00032 int z=0;
00033 int b,w;
00034 
00035 void reloj(){
00036      
00037     
00038      
00039      
00040    
00041     
00042    
00043     
00044     if(x==1){
00045         
00046     s.start();
00047       
00048         
00049         segundos2 =25- s.read();
00050         
00051         if(segundos2 == 0){
00052             segundos2=25;
00053             
00054             s.reset();
00055             s.start();
00056             
00057            
00058         }  
00059     
00060      
00061        t.start();
00062         
00063         segundos = t.read();
00064         if(segundos == 60){
00065             segundos=0;
00066             t.reset();
00067             minutos++;
00068            
00069         }
00070         if(minutos==60){
00071             minutos=0;
00072             horas++;
00073             
00074         }
00075         
00076          
00077     
00078   }
00079   
00080    
00081     
00082   
00083 }
00084 
00085 int main(){
00086    
00087      
00088    while(1){
00089        
00090        
00091        
00092    
00093     
00094      
00095         
00096        
00097      
00098         if(p==1){
00099          
00100        if(minutos==1){
00101            alarma=1;
00102            wait(1);
00103            alarma=0;
00104            }
00105            }
00106            
00107         if(p==2){
00108          
00109        if(minutos==1){
00110            alarma=1;
00111            wait(1);
00112            alarma=0;
00113            }
00114            }
00115            
00116         if(p==3){
00117          
00118        if(minutos==1){
00119            alarma=1;
00120            wait(1);
00121            alarma=0;
00122            }
00123            }
00124        
00125        
00126        if(p==4){
00127          
00128        if(minutos==1){
00129            alarma=1;
00130           
00131            lcd.cls(); 
00132            w=1;
00133     lcd.locate(0, 0); 
00134     lcd.printf("FIN DEL PARTIDO"); 
00135           t.stop();
00136           s.stop();
00137           s.reset();
00138           t.reset();
00139     lcd.locate(4, 1);
00140     lcd.printf("-L");
00141     
00142     lcd.locate(11, 1);
00143     lcd.printf("V-");
00144     
00145     lcd.locate(13, 1);
00146     lcd.printf("%d",v);
00147     
00148       lcd.locate(0, 1);
00149     lcd.printf("%d",l);
00150       
00151           
00152           
00153           
00154     
00155         
00156    
00157             
00158            }
00159            
00160      }else{
00161          lcd.locate(0, 0); 
00162     lcd.printf("T-"); 
00163 
00164     lcd.locate(4, 1);
00165     lcd.printf("-L");
00166     
00167     lcd.locate(11, 1);
00168     lcd.printf("V-");
00169     
00170     
00171     
00172     
00173     
00174      
00175         }
00176         
00177         
00178     
00179     
00180    
00181     
00182     
00183     
00184     if(boton1==1){
00185         x=1;
00186          
00187         
00188         }
00189         
00190         if(boton2==1){
00191         x=0;
00192           t.stop();
00193           s.stop();
00194           s.reset();
00195            segundos2=0;
00196            lcd.locate(14, 0); 
00197     lcd.printf("00");
00198         }
00199         
00200         
00201         
00202         if(w==1){
00203             wait(60);
00204             }else{
00205                  lcd.locate(14, 0); 
00206     lcd.printf("%d",segundos2);
00207     
00208     
00209        if(boton3==1){
00210             lcd.locate(12,0);
00211     lcd.printf(">");
00212             
00213           }else{  
00214         lcd.locate(12,0);
00215     lcd.printf("<");
00216     
00217     }
00218                 }
00219         
00220         
00221         
00222         if(boton2==1){
00223             
00224             wait(2);
00225             if(boton2==1){
00226           s.reset();  
00227           t.reset();
00228           minutos=0;
00229           segundos=0;
00230           segundos2=0;
00231           
00232           
00233     
00234          lcd.locate(2,0);//unidades de minuto
00235     lcd.printf("%d",minutos);
00236            
00237              lcd.locate(5,0);//unidades de segundo
00238     lcd.printf("0%d", segundos);  
00239     lcd.locate(4,0);
00240     lcd.printf(":");  
00241     
00242    
00243           //imprimir ceros
00244         }
00245         }
00246         
00247         
00248         
00249          if(minutos<10){
00250         lcd.locate(2,0);//unidades de minuto
00251     lcd.printf("0%d",minutos);
00252              reloj();
00253             }else{
00254     
00255     lcd.locate(2,0);//unidades de minuto
00256     lcd.printf("%d",minutos);
00257     }
00258     
00259    reloj();
00260         
00261         if(segundos<10){
00262           lcd.locate(5,0);//unidades de segundo
00263     lcd.printf("0%d", segundos);  
00264     lcd.locate(4,0);
00265     lcd.printf(":");
00266     
00267     
00268     reloj(); 
00269     
00270             
00271             }else{
00272     lcd.locate(5,0);//unidades de segundo
00273     lcd.printf("%d", segundos);
00274     lcd.locate(4,0);
00275     lcd.printf(":");
00276     
00277     
00278    reloj(); 
00279 
00280 }
00281 
00282 if(segundos2<10){
00283           
00284           lcd.locate(14, 0); 
00285     lcd.printf("0%d",segundos2); 
00286     
00287     
00288     //reloj(); 
00289     
00290             
00291             
00292     
00293     
00294     reloj(); 
00295     
00296             
00297             }
00298 
00299 
00300      if(boton4==1){
00301             l++;
00302             wait(.3);
00303             lcd.locate(0, 1);
00304     lcd.printf("%d",l);
00305             }
00306    
00307             
00308             if(boton5==1){
00309             v++;
00310             wait(.3);
00311             lcd.locate(13, 1);
00312     lcd.printf("%d",v);
00313             }
00314             
00315             
00316              if(boton6==1){
00317                 
00318             p++;
00319             wait(.3);
00320            lcd.locate(8, 1);
00321            
00322    lcd.printf("%d",p);
00323             }
00324             
00325             if(p==5){
00326                 p=-1;
00327                 
00328                 }
00329 
00330   
00331         
00332     }
00333 
00334 
00335 }
00336