Laboratorio informática industrial 5

Dependencies:   mbed

Committer:
elchef
Date:
Wed Mar 26 23:24:11 2014 +0000
Revision:
0:ab62d30dacdc
Child:
1:bc801083d70a
Laboratorio 5

Who changed what in which revision?

UserRevisionLine numberNew contents of line
elchef 0:ab62d30dacdc 1 #include "mbed.h"
elchef 0:ab62d30dacdc 2
elchef 0:ab62d30dacdc 3 struct players {
elchef 0:ab62d30dacdc 4 char name;
elchef 0:ab62d30dacdc 5 int score;
elchef 0:ab62d30dacdc 6 } player1, player2;
elchef 0:ab62d30dacdc 7
elchef 0:ab62d30dacdc 8 DigitalOut myled(LED3);
elchef 0:ab62d30dacdc 9 BusOut Display1 (D4, D5, D8, D7, D6, D3, D2);
elchef 0:ab62d30dacdc 10 BusOut Display2 (PTD2, PTD3, PTE1, PTE0, PTD1, PTD0, PTB0);
elchef 0:ab62d30dacdc 11 InterruptIn Bplayer1 (PTC2);
elchef 0:ab62d30dacdc 12 InterruptIn Bplayer2 (PTC3);
elchef 0:ab62d30dacdc 13 DigitalIn Boton3 (PTC4);
elchef 0:ab62d30dacdc 14 int numero;
elchef 0:ab62d30dacdc 15 Timer tiempo;
elchef 0:ab62d30dacdc 16
elchef 0:ab62d30dacdc 17 void Player1Score()
elchef 0:ab62d30dacdc 18 {
elchef 0:ab62d30dacdc 19 player1.score = player1.score+1;
elchef 0:ab62d30dacdc 20 tiempo.reset();
elchef 0:ab62d30dacdc 21 }
elchef 0:ab62d30dacdc 22 void Player2Score()
elchef 0:ab62d30dacdc 23 {
elchef 0:ab62d30dacdc 24 player2.score = player2.score+1;
elchef 0:ab62d30dacdc 25 tiempo.reset();
elchef 0:ab62d30dacdc 26 }
elchef 0:ab62d30dacdc 27 int CeroAlNueve(int paso)
elchef 0:ab62d30dacdc 28 {
elchef 0:ab62d30dacdc 29 int Valor = 0;
elchef 0:ab62d30dacdc 30 switch (paso) {
elchef 0:ab62d30dacdc 31 case 0:
elchef 0:ab62d30dacdc 32 Valor = 63;
elchef 0:ab62d30dacdc 33 break;
elchef 0:ab62d30dacdc 34 case 1:
elchef 0:ab62d30dacdc 35 Valor = 6;
elchef 0:ab62d30dacdc 36 break;
elchef 0:ab62d30dacdc 37 case 2:
elchef 0:ab62d30dacdc 38 Valor = 91;
elchef 0:ab62d30dacdc 39 break;
elchef 0:ab62d30dacdc 40 case 3:
elchef 0:ab62d30dacdc 41 Valor = 79;
elchef 0:ab62d30dacdc 42 break;
elchef 0:ab62d30dacdc 43 case 4:
elchef 0:ab62d30dacdc 44 Valor = 102;
elchef 0:ab62d30dacdc 45 break;
elchef 0:ab62d30dacdc 46 case 5:
elchef 0:ab62d30dacdc 47 Valor = 109;
elchef 0:ab62d30dacdc 48 break;
elchef 0:ab62d30dacdc 49 case 6:
elchef 0:ab62d30dacdc 50 Valor = 125;
elchef 0:ab62d30dacdc 51 break;
elchef 0:ab62d30dacdc 52 case 7:
elchef 0:ab62d30dacdc 53 Valor = 7;
elchef 0:ab62d30dacdc 54 break;
elchef 0:ab62d30dacdc 55 case 8:
elchef 0:ab62d30dacdc 56 Valor = 127;
elchef 0:ab62d30dacdc 57 break;
elchef 0:ab62d30dacdc 58 case 9:
elchef 0:ab62d30dacdc 59 Valor = 103;
elchef 0:ab62d30dacdc 60 break;
elchef 0:ab62d30dacdc 61 }
elchef 0:ab62d30dacdc 62 return Valor;
elchef 0:ab62d30dacdc 63 }
elchef 0:ab62d30dacdc 64
elchef 0:ab62d30dacdc 65 void PrintDisplay(int puntos1, int puntos2)
elchef 0:ab62d30dacdc 66 {
elchef 0:ab62d30dacdc 67 Display1 = CeroAlNueve(puntos1);
elchef 0:ab62d30dacdc 68 Display2 = CeroAlNueve(puntos2);
elchef 0:ab62d30dacdc 69 }
elchef 0:ab62d30dacdc 70
elchef 0:ab62d30dacdc 71 int main ()
elchef 0:ab62d30dacdc 72 {
elchef 0:ab62d30dacdc 73 tiempo.start();
elchef 0:ab62d30dacdc 74 srand (time(NULL));
elchef 0:ab62d30dacdc 75 player1.name = 'A';
elchef 0:ab62d30dacdc 76 player2.name = 'B';
elchef 0:ab62d30dacdc 77 numero = rand() % 10 + 1;
elchef 0:ab62d30dacdc 78 myled=1;
elchef 0:ab62d30dacdc 79
elchef 0:ab62d30dacdc 80 while(1) {
elchef 0:ab62d30dacdc 81 Bplayer1.rise(&Player1Score);
elchef 0:ab62d30dacdc 82 Bplayer2.rise(&Player2Score);
elchef 0:ab62d30dacdc 83 player1.name = 'A';
elchef 0:ab62d30dacdc 84 player2.name = 'B';
elchef 0:ab62d30dacdc 85 player1.score= 0;
elchef 0:ab62d30dacdc 86 player2.score = 0;
elchef 0:ab62d30dacdc 87 PrintDisplay(player1.score, player2.score);
elchef 0:ab62d30dacdc 88 while(tiempo.read() >= numero) {
elchef 0:ab62d30dacdc 89 myled=1;
elchef 0:ab62d30dacdc 90 }
elchef 0:ab62d30dacdc 91 if((player1.score || player2.score) == 10) {
elchef 0:ab62d30dacdc 92 player1.score= 0;
elchef 0:ab62d30dacdc 93 player2.score = 0;
elchef 0:ab62d30dacdc 94 }
elchef 0:ab62d30dacdc 95 if(Boton3 == 1) {
elchef 0:ab62d30dacdc 96 return 0;
elchef 0:ab62d30dacdc 97 }
elchef 0:ab62d30dacdc 98 }
elchef 0:ab62d30dacdc 99 }