Ejercicio realizado por: HU, Julian y LOPEZ, Gabriel.

Dependencies:   mbed

Committer:
GabiLopez
Date:
Sat May 25 18:47:44 2019 +0000
Revision:
0:ff8d1aea6fb4
Child:
1:06553fdedc7e
no funca;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
GabiLopez 0:ff8d1aea6fb4 1 #include "mbed.h"
GabiLopez 0:ff8d1aea6fb4 2
GabiLopez 0:ff8d1aea6fb4 3 DigitalIn pulsador1 (PTC12);
GabiLopez 0:ff8d1aea6fb4 4 DigitalIn pulsador2 (PTC13);
GabiLopez 0:ff8d1aea6fb4 5 DigitalIn pulsador3 (PTC16);
GabiLopez 0:ff8d1aea6fb4 6
GabiLopez 0:ff8d1aea6fb4 7 DigitalOut ledrojo(LED_RED);
GabiLopez 0:ff8d1aea6fb4 8 DigitalOut ledazul(LED_BLUE);
GabiLopez 0:ff8d1aea6fb4 9 DigitalOut ledverde(LED_GREEN);
GabiLopez 0:ff8d1aea6fb4 10
GabiLopez 0:ff8d1aea6fb4 11 Ticker pulso1;
GabiLopez 0:ff8d1aea6fb4 12 Ticker pulso2;
GabiLopez 0:ff8d1aea6fb4 13 Ticker pulso3;
GabiLopez 0:ff8d1aea6fb4 14 Ticker aviso;
GabiLopez 0:ff8d1aea6fb4 15 Ticker mostrar;
GabiLopez 0:ff8d1aea6fb4 16
GabiLopez 0:ff8d1aea6fb4 17
GabiLopez 0:ff8d1aea6fb4 18 void detector1();
GabiLopez 0:ff8d1aea6fb4 19 void detector2();
GabiLopez 0:ff8d1aea6fb4 20 void detector3();
GabiLopez 0:ff8d1aea6fb4 21 void intermitencia();
GabiLopez 0:ff8d1aea6fb4 22
GabiLopez 0:ff8d1aea6fb4 23 int verificacion1=0, verificacion2=0, verificacion3=0, rebote1=0, rebote2=0, rebote3=0;
GabiLopez 0:ff8d1aea6fb4 24 char secuencia[5], turno=0;
GabiLopez 0:ff8d1aea6fb4 25 int juego=0, obtener_num_random=0, i=0, turno_actual=0;
GabiLopez 0:ff8d1aea6fb4 26
GabiLopez 0:ff8d1aea6fb4 27
GabiLopez 0:ff8d1aea6fb4 28 int main()
GabiLopez 0:ff8d1aea6fb4 29 {
GabiLopez 0:ff8d1aea6fb4 30 __enable_irq();
GabiLopez 0:ff8d1aea6fb4 31
GabiLopez 0:ff8d1aea6fb4 32 pulsador1.mode(PullUp);
GabiLopez 0:ff8d1aea6fb4 33 pulsador2.mode(PullUp);
GabiLopez 0:ff8d1aea6fb4 34 pulsador3.mode(PullUp);
GabiLopez 0:ff8d1aea6fb4 35
GabiLopez 0:ff8d1aea6fb4 36 pulso1.attach(&detector1,0.01);
GabiLopez 0:ff8d1aea6fb4 37 pulso2.attach(&detector2,0.01);
GabiLopez 0:ff8d1aea6fb4 38 pulso3.attach(&detector3,0.01);
GabiLopez 0:ff8d1aea6fb4 39
GabiLopez 0:ff8d1aea6fb4 40 ledrojo=1;
GabiLopez 0:ff8d1aea6fb4 41 ledverde=1;
GabiLopez 0:ff8d1aea6fb4 42 ledazul=1;
GabiLopez 0:ff8d1aea6fb4 43
GabiLopez 0:ff8d1aea6fb4 44 srand(time(NULL));
GabiLopez 0:ff8d1aea6fb4 45
GabiLopez 0:ff8d1aea6fb4 46 if (juego==0)
GabiLopez 0:ff8d1aea6fb4 47 aviso.attach(&intermitencia, 1);
GabiLopez 0:ff8d1aea6fb4 48
GabiLopez 0:ff8d1aea6fb4 49 while (juego==0) {
GabiLopez 0:ff8d1aea6fb4 50 if (pulsador2==0 && juego==0) {
GabiLopez 0:ff8d1aea6fb4 51 juego=1;
GabiLopez 0:ff8d1aea6fb4 52 }
GabiLopez 0:ff8d1aea6fb4 53 }
GabiLopez 0:ff8d1aea6fb4 54
GabiLopez 0:ff8d1aea6fb4 55 while (true) {
GabiLopez 0:ff8d1aea6fb4 56 if (juego==1 && turno<5) {
GabiLopez 0:ff8d1aea6fb4 57 turno_actual=rand () % 3;
GabiLopez 0:ff8d1aea6fb4 58 secuencia[turno]=turno_actual;
GabiLopez 0:ff8d1aea6fb4 59 turno++;
GabiLopez 0:ff8d1aea6fb4 60 }
GabiLopez 0:ff8d1aea6fb4 61
GabiLopez 0:ff8d1aea6fb4 62 for (i=0;i<turno;i++){
GabiLopez 0:ff8d1aea6fb4 63 switch(turno_actual) {
GabiLopez 0:ff8d1aea6fb4 64
GabiLopez 0:ff8d1aea6fb4 65 case 0:
GabiLopez 0:ff8d1aea6fb4 66 ledrojo=0;
GabiLopez 0:ff8d1aea6fb4 67 ledverde=1;
GabiLopez 0:ff8d1aea6fb4 68 ledazul=1;
GabiLopez 0:ff8d1aea6fb4 69 break;
GabiLopez 0:ff8d1aea6fb4 70
GabiLopez 0:ff8d1aea6fb4 71 case 1:
GabiLopez 0:ff8d1aea6fb4 72 ledrojo=1;
GabiLopez 0:ff8d1aea6fb4 73 ledverde=0;
GabiLopez 0:ff8d1aea6fb4 74 ledazul=1;
GabiLopez 0:ff8d1aea6fb4 75 break;
GabiLopez 0:ff8d1aea6fb4 76
GabiLopez 0:ff8d1aea6fb4 77 case 2:
GabiLopez 0:ff8d1aea6fb4 78 ledrojo=1;
GabiLopez 0:ff8d1aea6fb4 79 ledverde=1;
GabiLopez 0:ff8d1aea6fb4 80 ledazul=0;
GabiLopez 0:ff8d1aea6fb4 81 break;
GabiLopez 0:ff8d1aea6fb4 82 }
GabiLopez 0:ff8d1aea6fb4 83 }
GabiLopez 0:ff8d1aea6fb4 84 }
GabiLopez 0:ff8d1aea6fb4 85
GabiLopez 0:ff8d1aea6fb4 86 }
GabiLopez 0:ff8d1aea6fb4 87
GabiLopez 0:ff8d1aea6fb4 88 void detector1()
GabiLopez 0:ff8d1aea6fb4 89 {
GabiLopez 0:ff8d1aea6fb4 90 if (pulsador1==0 && verificacion1==0) {
GabiLopez 0:ff8d1aea6fb4 91 verificacion1=1;
GabiLopez 0:ff8d1aea6fb4 92 rebote1=4;
GabiLopez 0:ff8d1aea6fb4 93 }
GabiLopez 0:ff8d1aea6fb4 94 if (pulsador1==0 && verificacion1==1) {
GabiLopez 0:ff8d1aea6fb4 95 if (rebote1>0)
GabiLopez 0:ff8d1aea6fb4 96 rebote1--;
GabiLopez 0:ff8d1aea6fb4 97 }
GabiLopez 0:ff8d1aea6fb4 98 if(rebote1==0 && verificacion1==1 && pulsador1==1) {
GabiLopez 0:ff8d1aea6fb4 99 verificacion1=0;
GabiLopez 0:ff8d1aea6fb4 100 }
GabiLopez 0:ff8d1aea6fb4 101 }
GabiLopez 0:ff8d1aea6fb4 102
GabiLopez 0:ff8d1aea6fb4 103 void detector2()
GabiLopez 0:ff8d1aea6fb4 104 {
GabiLopez 0:ff8d1aea6fb4 105 if (pulsador2==0 && verificacion2==0) {
GabiLopez 0:ff8d1aea6fb4 106 verificacion2=1;
GabiLopez 0:ff8d1aea6fb4 107 rebote2=4;
GabiLopez 0:ff8d1aea6fb4 108 }
GabiLopez 0:ff8d1aea6fb4 109 if (pulsador2==0 && verificacion2==1) {
GabiLopez 0:ff8d1aea6fb4 110 if (rebote2>0)
GabiLopez 0:ff8d1aea6fb4 111 rebote2--;
GabiLopez 0:ff8d1aea6fb4 112 }
GabiLopez 0:ff8d1aea6fb4 113 if(rebote2==0 && verificacion2==1 && pulsador2==1) {
GabiLopez 0:ff8d1aea6fb4 114 verificacion2=0;
GabiLopez 0:ff8d1aea6fb4 115 }
GabiLopez 0:ff8d1aea6fb4 116 }
GabiLopez 0:ff8d1aea6fb4 117
GabiLopez 0:ff8d1aea6fb4 118 void detector3()
GabiLopez 0:ff8d1aea6fb4 119 {
GabiLopez 0:ff8d1aea6fb4 120 if (pulsador3==0 && verificacion3==0) {
GabiLopez 0:ff8d1aea6fb4 121 verificacion3=1;
GabiLopez 0:ff8d1aea6fb4 122 rebote3=4;
GabiLopez 0:ff8d1aea6fb4 123 }
GabiLopez 0:ff8d1aea6fb4 124 if (pulsador3==0 && verificacion3==1) {
GabiLopez 0:ff8d1aea6fb4 125 if (rebote3>0)
GabiLopez 0:ff8d1aea6fb4 126 rebote3--;
GabiLopez 0:ff8d1aea6fb4 127 }
GabiLopez 0:ff8d1aea6fb4 128 if(rebote3==0 && verificacion3==1 && pulsador3==1) {
GabiLopez 0:ff8d1aea6fb4 129 verificacion3=0;
GabiLopez 0:ff8d1aea6fb4 130 }
GabiLopez 0:ff8d1aea6fb4 131 }
GabiLopez 0:ff8d1aea6fb4 132
GabiLopez 0:ff8d1aea6fb4 133 void intermitencia()
GabiLopez 0:ff8d1aea6fb4 134 {
GabiLopez 0:ff8d1aea6fb4 135 if (juego==0) {
GabiLopez 0:ff8d1aea6fb4 136 printf("-------------------ATENCION---------------------\n");
GabiLopez 0:ff8d1aea6fb4 137 printf("Presione el pulsador del medio para comenzar\n");
GabiLopez 0:ff8d1aea6fb4 138 ledrojo=!ledrojo;
GabiLopez 0:ff8d1aea6fb4 139 }
GabiLopez 0:ff8d1aea6fb4 140 if (juego==1) {
GabiLopez 0:ff8d1aea6fb4 141 printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
GabiLopez 0:ff8d1aea6fb4 142 printf("-----------------ATENCION---------------------\n");
GabiLopez 0:ff8d1aea6fb4 143 printf("QUE COMIENCE EL JUEGO\n");
GabiLopez 0:ff8d1aea6fb4 144 printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
GabiLopez 0:ff8d1aea6fb4 145 aviso.detach();
GabiLopez 0:ff8d1aea6fb4 146 }
GabiLopez 0:ff8d1aea6fb4 147 }
GabiLopez 0:ff8d1aea6fb4 148
GabiLopez 0:ff8d1aea6fb4 149