-
-
Save ltuozzo/3a1aa8712c3e65a332a7fcce854346b1 to your computer and use it in GitHub Desktop.
Tp version final
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef __TDATO_H | |
#define __TDATO_H | |
#ifndef __MAX | |
#define __MAX 8 | |
#endif | |
typedef char TdatoC; | |
typedef int TdatoE; | |
#endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "tdato.h" | |
#ifndef __PILAE_H | |
#define __PILAE_H | |
#include "TDato.h" | |
struct pila{ | |
int Cima; | |
TdatoE Elem[__MAX]; | |
}; | |
typedef struct pila TpilaE; | |
int pllena (TpilaE *p){ | |
return p->Cima == __MAX-1; | |
} | |
int pvacia (TpilaE *p){ | |
return p->Cima == -1; | |
} | |
void pcrear(TpilaE *p){ | |
p->Cima=-1; | |
} | |
void pponer (TpilaE *p, TdatoE x){ | |
p->Cima++; | |
p->Elem[p->Cima] = x; | |
} | |
void psacar(TpilaE *p, TdatoE *x){ | |
*x = p->Elem[p->Cima]; | |
p->Cima--; | |
} | |
#endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "tpila.h" | |
int led[] = {10,9,8,7,6,5,4,2}; | |
int puntaje = 0; | |
int punto = 2; | |
int puntajeStart = 8; | |
int contador = 0; | |
int botonA = 12; //Igualar a la posicion del boton A (equipo A) | |
int botonB = 11; //Igualar a la posicion del boton B (equipo B) | |
int botonC = 13; //Igualar a la posicion del boton C (Reiniciar el juego) | |
int buzzer = 1; | |
int pin = 4; | |
int tones[] = {261, 277, 294, 311, 330, 349, 370, 392}; // musica 1 | |
int song[] = {261, 349, 392, 440, 392, 330, -10, 261, 349, 392, 440, 392}; //musica 2 | |
int numTones = 7; | |
int esta = 0; | |
pila p; | |
void setup() { | |
for ( int pinl=0; pinl< 8; pinl++){ | |
pinMode (led[pinl], OUTPUT); | |
} | |
pinMode(buzzer, OUTPUT); | |
pinMode(botonA, INPUT); | |
pinMode(botonB, INPUT); | |
pinMode(botonC,INPUT); | |
pcrear (&p) ; | |
} | |
void loop() { | |
//Empezar juego | |
if (digitalRead(botonC) == HIGH) { | |
for (int i = 0; i < 8; i++){ | |
digitalWrite(led[i], LOW); | |
delay(100); | |
} | |
for (int i = 0; i < 4; i++){ | |
digitalWrite(led[i], HIGH); | |
delay(100); | |
pponer(&p, contador); | |
} | |
//Musica intro | |
for (int i = 0; i < numTones; i++){ | |
tone(buzzer, tones[i]); | |
delay(500); | |
} | |
noTone(buzzer); | |
puntaje = 0; | |
pin=4; | |
esta=1; | |
} | |
if (digitalRead(botonA) == HIGH & esta==1) { //puntaje jugador 1 | |
puntaje++; | |
tone(buzzer, 1500); // envia señal al buzzer | |
delay (200); | |
noTone(buzzer); // para el sonido | |
delay(250); | |
} | |
if (digitalRead(botonB) == HIGH & esta==1) { //puntaje jugador 2 | |
puntaje--; | |
tone(buzzer, 1000); | |
delay (200); | |
noTone(buzzer); | |
delay(250); | |
} | |
if (puntaje == punto) { //punto jugador 1 | |
digitalWrite(led[pin], HIGH); | |
pin++; | |
puntaje = 0; | |
pponer(&p, contador); | |
} | |
else { | |
if (puntaje == -punto){ //punto jugador 2 | |
pin--; | |
digitalWrite(led[pin], LOW); | |
puntaje = 0; | |
psacar(&p, &contador); | |
} | |
} | |
//Verificar si la pila esta llena o vacia para terminar el juego | |
if ((pllena(&p)) && (esta == 1)) { | |
for (int i = 0; i < numTones; i++){ //musica final | |
tone(buzzer, song[i]); | |
delay(500); | |
} | |
noTone(buzzer); | |
for (int i = 0; i < 8; i++){ | |
digitalWrite(led[i], LOW); | |
delay(100); | |
esta =0; | |
} | |
} | |
if ((pvacia(&p)) && (esta == 1)) { | |
for (int i = 0; i < numTones; i++){ //musica final | |
tone(buzzer, song[i]); | |
delay(500); | |
} | |
noTone(buzzer); | |
for (int i = 0; i < 8; i++){ | |
digitalWrite(led[i], LOW); | |
delay(100); | |
esta =0; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment