![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Laboratorio informática industrial 5
Diff: main.cpp
- Revision:
- 0:ab62d30dacdc
- Child:
- 1:bc801083d70a
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Wed Mar 26 23:24:11 2014 +0000 @@ -0,0 +1,99 @@ +#include "mbed.h" + +struct players { + char name; + int score; +} player1, player2; + +DigitalOut myled(LED3); +BusOut Display1 (D4, D5, D8, D7, D6, D3, D2); +BusOut Display2 (PTD2, PTD3, PTE1, PTE0, PTD1, PTD0, PTB0); +InterruptIn Bplayer1 (PTC2); +InterruptIn Bplayer2 (PTC3); +DigitalIn Boton3 (PTC4); +int numero; +Timer tiempo; + +void Player1Score() +{ + player1.score = player1.score+1; + tiempo.reset(); +} +void Player2Score() +{ + player2.score = player2.score+1; + tiempo.reset(); +} +int CeroAlNueve(int paso) +{ + int Valor = 0; + switch (paso) { + case 0: + Valor = 63; + break; + case 1: + Valor = 6; + break; + case 2: + Valor = 91; + break; + case 3: + Valor = 79; + break; + case 4: + Valor = 102; + break; + case 5: + Valor = 109; + break; + case 6: + Valor = 125; + break; + case 7: + Valor = 7; + break; + case 8: + Valor = 127; + break; + case 9: + Valor = 103; + break; + } + return Valor; +} + +void PrintDisplay(int puntos1, int puntos2) +{ + Display1 = CeroAlNueve(puntos1); + Display2 = CeroAlNueve(puntos2); +} + +int main () +{ + tiempo.start(); + srand (time(NULL)); + player1.name = 'A'; + player2.name = 'B'; + numero = rand() % 10 + 1; + myled=1; + + while(1) { + Bplayer1.rise(&Player1Score); + Bplayer2.rise(&Player2Score); + player1.name = 'A'; + player2.name = 'B'; + player1.score= 0; + player2.score = 0; + PrintDisplay(player1.score, player2.score); + while(tiempo.read() >= numero) { + myled=1; + } + if((player1.score || player2.score) == 10) { + player1.score= 0; + player2.score = 0; + } + if(Boton3 == 1) { + return 0; + } + } +}