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.
Diff: main.cpp
- Revision:
- 0:3ef421501119
diff -r 000000000000 -r 3ef421501119 main.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Tue Jun 07 02:28:09 2022 +0000
@@ -0,0 +1,321 @@
+#include "mbed.h"
+#define CANT_LEDS 7
+
+
+BusOut Leds(PTC12,PTC13,PTC16,PTC17,PTA16,PTA17,PTE31,PTD6);
+DigitalOut L1(PTC12);
+DigitalOut L2(PTC13);
+DigitalOut L3(PTC16);
+DigitalOut L4(PTC17);
+DigitalOut L5(PTA16);
+DigitalOut L6(PTA17);
+DigitalOut L7(PTE31);
+DigitalOut L8(PTD6);
+DigitalIn P1(PTD7);
+DigitalIn P2(PTC7);
+
+DigitalOut DISPLAY1(PTE20);
+DigitalOut A(PTE5);
+DigitalOut B(PTE4);
+DigitalOut C(PTE3);
+DigitalOut D(PTE2);
+DigitalOut E(PTB11);
+DigitalOut F(PTB10);
+DigitalOut G(PTB9);
+DigitalOut DISPLAY2(PTB8);
+
+Ticker tick;
+Serial pc(USBTX, USBRX);
+void EstadoJuego();
+void display(int x);
+char decenas;
+char unidades;
+int d[10] = {0b1111110 , 0b0110000 , 0b1101101 , 0b1111001 , 0b0110011 , 0b1011011 , 0b1011111 , 0b1110000 , 0b1111111 , 0b1111011};
+int tiempo=0,tiempo2=0,tiempo3=0,Estado=0,valor=0,mux_display=0;
+int PuntajeJ1=0,PuntajeJ2=0,t1=0,LedParado,pj=0;
+
+void interrupcion()
+{
+ tiempo++;
+ tiempo2++;
+ tiempo3++;
+ mux_display++;
+
+ if(mux_display==1)
+ {
+ DISPLAY2=1;
+ display(decenas);
+ DISPLAY1=0;}
+ if(mux_display==21)
+ {
+ DISPLAY1=1;
+ display(unidades);
+ DISPLAY2=0;}
+ if(mux_display==41)
+ {mux_display=0;}
+
+
+}
+
+int main()
+{
+ tick.attach(&interrupcion, 0.001); // setup ticker to call flip every 0.7 seconds
+ P1.mode(PullNone);
+ P2.mode(PullNone);
+ L1=0;
+ L2=0;
+ L3=0;
+ L4=0;
+ L5=0;
+ L6=0;
+ L7=0;
+ L8=0;
+ while(1)
+ {
+ EstadoJuego();
+ }
+
+
+}
+void EstadoJuego()
+{
+ valor=PuntajeJ1*10+PuntajeJ2;
+ decenas = valor/10;
+ unidades = valor%10;
+ switch(Estado)
+ {
+ case 0:
+ if (tiempo>=0 && tiempo<500)
+ {
+ L1=1;
+ L2=1;
+ L3=1;
+ L4=1;
+ L5=1;
+ L6=1;
+ L7=1;
+ L8=1;
+ A=1;
+ B=1;
+ C=1;
+ D=1;
+ E=1;
+ F=1;
+ G=1;}
+ if(tiempo>=501 && tiempo<1000)
+ {
+ L1=0;
+ L2=0;
+ L3=0;
+ L4=0;
+ L5=0;
+ L6=0;
+ L7=0;
+ L8=0;
+ A=0;
+ B=0;
+ C=0;
+ D=0;
+ E=0;
+ F=0;
+ G=0;}
+ if(tiempo==1001)
+ {tiempo=0;}
+ if(P1==1 && P2==1)
+ {
+ tiempo=0;
+ tiempo3=0;
+ Estado=1;
+ }
+ break;
+
+ case 1:
+ pj=0;
+ if(tiempo>=0 && tiempo<99)
+ {
+ L2=0;
+ L1=1;}
+
+ if(tiempo>=100 && tiempo <199)
+ {
+ L1=0;
+ L2=1;}
+
+ if(tiempo>=200 && tiempo<299)
+ {
+ L2=0;
+ L3=1;}
+
+ if(tiempo>=300 && tiempo<399)
+ {
+ L3=0;
+ L4=1;}
+ if(tiempo>=400 && tiempo<499)
+ {
+ L4=0;
+ L5=1;}
+ if(tiempo>=500 && tiempo<599)
+ {
+ L5=0;
+ L6=1;}
+ if(tiempo>=600 && tiempo<699)
+ {
+ L6=0;
+ L7=1;}
+ if(tiempo>=700 && tiempo<799)
+ {
+ L7=0;
+ L8=1;}
+ if(tiempo>=800 && tiempo<899)
+ {
+ L8=0;
+ L7=1;}
+ if(tiempo>=900 && tiempo<999)
+ {
+ L7=0;
+ L6=1;}
+ if(tiempo>=1000 && tiempo<1099)
+ {
+ L6=0;
+ L5=1;}
+ if(tiempo>=1100 && tiempo<1199)
+ {
+ L5=0;
+ L4=1;}
+ if(tiempo>=1200 && tiempo<1299)
+ {
+ L4=0;
+ L3=1;}
+ if(tiempo>=1300 && tiempo<1399)
+ {
+ L3=0;
+ L2=1;}
+ if(tiempo==1400 )
+ {
+ tiempo=0;}
+ if(tiempo3>=2000)
+ {
+ for(int i=0;i<=7;i++)
+ {
+ if(P1==1 || P2==1)
+ {
+ t1=tiempo;
+ if(Leds[i]==1){
+ LedParado=i;
+ tiempo2=0;}
+ Estado=2;}
+ }
+ if(P1==1 && L1==1)
+ {
+ t1=tiempo;
+ LedParado=0;
+ PuntajeJ1++;
+ tiempo2=0;
+ pj=1;
+ Estado=2;}
+
+ if(P2==1 && L8==1)
+ {
+ t1=tiempo;
+ LedParado=7;
+ PuntajeJ2++;
+ tiempo2=0;
+ pj=1;
+ Estado=2;}
+ }
+ break;
+
+ case 2:
+
+ for(int i=0;i<=7;i++)
+ {
+ Leds[i]==0;
+ }
+ if(tiempo2>=0 && tiempo2<2001)
+ {
+ Leds[LedParado]=1;}
+ if(tiempo2>=2001)
+ {
+ Leds[LedParado]=0;
+ tiempo=t1;
+ Estado=1;
+ }
+ if(pj==1)
+ {
+ pc.printf("Puntaje J1: %d\n",PuntajeJ1);
+ pc.printf("Puntaje J2: %d\n",PuntajeJ2);}
+ pj=0;
+ if(PuntajeJ1==5)
+ {
+ pc.printf("Partida Terminada, Jugador 1 Gana\n");
+ tiempo2=0;
+ Estado=3;}
+ if(PuntajeJ2==5)
+ {
+ pc.printf("Partida Terminada, Jugador 2 Gana\n");
+ tiempo2=0;
+ Estado=3;}
+ break;
+ case 3:
+ if(PuntajeJ1==5 || PuntajeJ2==5)
+ {
+ tiempo=0;
+ if (tiempo>=0 && tiempo<200)
+ {
+ L1=1;
+ L2=1;
+ L3=1;
+ L4=1;
+ L5=1;
+ L6=1;
+ L7=1;
+ L8=1;
+ }
+ if(tiempo>=201 && tiempo<400)
+ {
+ L1=0;
+ L2=0;
+ L3=0;
+ L4=0;
+ L5=0;
+ L6=0;
+ L7=0;
+ L8=0;}
+ if(tiempo==401)
+ {tiempo=0;}
+ if(tiempo2>=1000)
+ {
+ if(PuntajeJ1==5)
+ {
+ if(P1==1)
+ {
+ PuntajeJ1=0;
+ PuntajeJ2=0;
+ Estado=0;}}
+ if(PuntajeJ2==5)
+ {
+ if(P2==1)
+ {
+ PuntajeJ1=0;
+ PuntajeJ2=0;
+ Estado=0;}}}
+ if(tiempo2>=10000)
+ {
+ PuntajeJ1=0;
+ PuntajeJ2=0;
+ Estado=0;}}
+ break;}}
+
+void display(int x)
+{
+ A= (d[x] & 0b1000000)>>6;
+ B= (d[x] & 0b100000)>>5;
+ C= (d[x] & 0b10000)>>4;
+ D= (d[x] & 0b1000)>>3;
+ E= (d[x] & 0b100)>>2;
+ F= (d[x] & 0b10)>>1;
+ G= (d[x] & 1);}
+
+
+
+