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.
main.cpp
00001 #include "mbed.h" 00002 #define CANT_LEDS 7 00003 00004 00005 BusOut Leds(PTC12,PTC13,PTC16,PTC17,PTA16,PTA17,PTE31,PTD6); 00006 DigitalOut L1(PTC12); 00007 DigitalOut L2(PTC13); 00008 DigitalOut L3(PTC16); 00009 DigitalOut L4(PTC17); 00010 DigitalOut L5(PTA16); 00011 DigitalOut L6(PTA17); 00012 DigitalOut L7(PTE31); 00013 DigitalOut L8(PTD6); 00014 DigitalIn P1(PTD7); 00015 DigitalIn P2(PTC7); 00016 00017 DigitalOut DISPLAY1(PTE20); 00018 DigitalOut A(PTE5); 00019 DigitalOut B(PTE4); 00020 DigitalOut C(PTE3); 00021 DigitalOut D(PTE2); 00022 DigitalOut E(PTB11); 00023 DigitalOut F(PTB10); 00024 DigitalOut G(PTB9); 00025 DigitalOut DISPLAY2(PTB8); 00026 00027 Ticker tick; 00028 Serial pc(USBTX, USBRX); 00029 void EstadoJuego(); 00030 void display(int x); 00031 char decenas; 00032 char unidades; 00033 int d[10] = {0b1111110 , 0b0110000 , 0b1101101 , 0b1111001 , 0b0110011 , 0b1011011 , 0b1011111 , 0b1110000 , 0b1111111 , 0b1111011}; 00034 int tiempo=0,tiempo2=0,tiempo3=0,Estado=0,valor=0,mux_display=0; 00035 int PuntajeJ1=0,PuntajeJ2=0,t1=0,LedParado,pj=0; 00036 00037 void interrupcion() 00038 { 00039 tiempo++; 00040 tiempo2++; 00041 tiempo3++; 00042 mux_display++; 00043 00044 if(mux_display==1) 00045 { 00046 DISPLAY2=1; 00047 display(decenas); 00048 DISPLAY1=0;} 00049 if(mux_display==21) 00050 { 00051 DISPLAY1=1; 00052 display(unidades); 00053 DISPLAY2=0;} 00054 if(mux_display==41) 00055 {mux_display=0;} 00056 00057 00058 } 00059 00060 int main() 00061 { 00062 tick.attach(&interrupcion, 0.001); // setup ticker to call flip every 0.7 seconds 00063 P1.mode(PullNone); 00064 P2.mode(PullNone); 00065 L1=0; 00066 L2=0; 00067 L3=0; 00068 L4=0; 00069 L5=0; 00070 L6=0; 00071 L7=0; 00072 L8=0; 00073 while(1) 00074 { 00075 EstadoJuego(); 00076 } 00077 00078 00079 } 00080 void EstadoJuego() 00081 { 00082 valor=PuntajeJ1*10+PuntajeJ2; 00083 decenas = valor/10; 00084 unidades = valor%10; 00085 switch(Estado) 00086 { 00087 case 0: 00088 if (tiempo>=0 && tiempo<500) 00089 { 00090 L1=1; 00091 L2=1; 00092 L3=1; 00093 L4=1; 00094 L5=1; 00095 L6=1; 00096 L7=1; 00097 L8=1; 00098 A=1; 00099 B=1; 00100 C=1; 00101 D=1; 00102 E=1; 00103 F=1; 00104 G=1;} 00105 if(tiempo>=501 && tiempo<1000) 00106 { 00107 L1=0; 00108 L2=0; 00109 L3=0; 00110 L4=0; 00111 L5=0; 00112 L6=0; 00113 L7=0; 00114 L8=0; 00115 A=0; 00116 B=0; 00117 C=0; 00118 D=0; 00119 E=0; 00120 F=0; 00121 G=0;} 00122 if(tiempo==1001) 00123 {tiempo=0;} 00124 if(P1==1 && P2==1) 00125 { 00126 tiempo=0; 00127 tiempo3=0; 00128 Estado=1; 00129 } 00130 break; 00131 00132 case 1: 00133 pj=0; 00134 if(tiempo>=0 && tiempo<99) 00135 { 00136 L2=0; 00137 L1=1;} 00138 00139 if(tiempo>=100 && tiempo <199) 00140 { 00141 L1=0; 00142 L2=1;} 00143 00144 if(tiempo>=200 && tiempo<299) 00145 { 00146 L2=0; 00147 L3=1;} 00148 00149 if(tiempo>=300 && tiempo<399) 00150 { 00151 L3=0; 00152 L4=1;} 00153 if(tiempo>=400 && tiempo<499) 00154 { 00155 L4=0; 00156 L5=1;} 00157 if(tiempo>=500 && tiempo<599) 00158 { 00159 L5=0; 00160 L6=1;} 00161 if(tiempo>=600 && tiempo<699) 00162 { 00163 L6=0; 00164 L7=1;} 00165 if(tiempo>=700 && tiempo<799) 00166 { 00167 L7=0; 00168 L8=1;} 00169 if(tiempo>=800 && tiempo<899) 00170 { 00171 L8=0; 00172 L7=1;} 00173 if(tiempo>=900 && tiempo<999) 00174 { 00175 L7=0; 00176 L6=1;} 00177 if(tiempo>=1000 && tiempo<1099) 00178 { 00179 L6=0; 00180 L5=1;} 00181 if(tiempo>=1100 && tiempo<1199) 00182 { 00183 L5=0; 00184 L4=1;} 00185 if(tiempo>=1200 && tiempo<1299) 00186 { 00187 L4=0; 00188 L3=1;} 00189 if(tiempo>=1300 && tiempo<1399) 00190 { 00191 L3=0; 00192 L2=1;} 00193 if(tiempo==1400 ) 00194 { 00195 tiempo=0;} 00196 if(tiempo3>=2000) 00197 { 00198 for(int i=0;i<=7;i++) 00199 { 00200 if(P1==1 || P2==1) 00201 { 00202 t1=tiempo; 00203 if(Leds[i]==1){ 00204 LedParado=i; 00205 tiempo2=0;} 00206 Estado=2;} 00207 } 00208 if(P1==1 && L1==1) 00209 { 00210 t1=tiempo; 00211 LedParado=0; 00212 PuntajeJ1++; 00213 tiempo2=0; 00214 pj=1; 00215 Estado=2;} 00216 00217 if(P2==1 && L8==1) 00218 { 00219 t1=tiempo; 00220 LedParado=7; 00221 PuntajeJ2++; 00222 tiempo2=0; 00223 pj=1; 00224 Estado=2;} 00225 } 00226 break; 00227 00228 case 2: 00229 00230 for(int i=0;i<=7;i++) 00231 { 00232 Leds[i]==0; 00233 } 00234 if(tiempo2>=0 && tiempo2<2001) 00235 { 00236 Leds[LedParado]=1;} 00237 if(tiempo2>=2001) 00238 { 00239 Leds[LedParado]=0; 00240 tiempo=t1; 00241 Estado=1; 00242 } 00243 if(pj==1) 00244 { 00245 pc.printf("Puntaje J1: %d\n",PuntajeJ1); 00246 pc.printf("Puntaje J2: %d\n",PuntajeJ2);} 00247 pj=0; 00248 if(PuntajeJ1==5) 00249 { 00250 pc.printf("Partida Terminada, Jugador 1 Gana\n"); 00251 tiempo2=0; 00252 Estado=3;} 00253 if(PuntajeJ2==5) 00254 { 00255 pc.printf("Partida Terminada, Jugador 2 Gana\n"); 00256 tiempo2=0; 00257 Estado=3;} 00258 break; 00259 case 3: 00260 if(PuntajeJ1==5 || PuntajeJ2==5) 00261 { 00262 tiempo=0; 00263 if (tiempo>=0 && tiempo<200) 00264 { 00265 L1=1; 00266 L2=1; 00267 L3=1; 00268 L4=1; 00269 L5=1; 00270 L6=1; 00271 L7=1; 00272 L8=1; 00273 } 00274 if(tiempo>=201 && tiempo<400) 00275 { 00276 L1=0; 00277 L2=0; 00278 L3=0; 00279 L4=0; 00280 L5=0; 00281 L6=0; 00282 L7=0; 00283 L8=0;} 00284 if(tiempo==401) 00285 {tiempo=0;} 00286 if(tiempo2>=1000) 00287 { 00288 if(PuntajeJ1==5) 00289 { 00290 if(P1==1) 00291 { 00292 PuntajeJ1=0; 00293 PuntajeJ2=0; 00294 Estado=0;}} 00295 if(PuntajeJ2==5) 00296 { 00297 if(P2==1) 00298 { 00299 PuntajeJ1=0; 00300 PuntajeJ2=0; 00301 Estado=0;}}} 00302 if(tiempo2>=10000) 00303 { 00304 PuntajeJ1=0; 00305 PuntajeJ2=0; 00306 Estado=0;}} 00307 break;}} 00308 00309 void display(int x) 00310 { 00311 A= (d[x] & 0b1000000)>>6; 00312 B= (d[x] & 0b100000)>>5; 00313 C= (d[x] & 0b10000)>>4; 00314 D= (d[x] & 0b1000)>>3; 00315 E= (d[x] & 0b100)>>2; 00316 F= (d[x] & 0b10)>>1; 00317 G= (d[x] & 1);} 00318 00319 00320 00321
Generated on Thu Jul 14 2022 19:25:00 by
1.7.2