-
-
Save ltuozzo/b9b180753bb4a9a78df4954a0e1cbf45 to your computer and use it in GitHub Desktop.
Juego de la cuerda
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
int arreglo[] = {0,1,2,3,4,5,6,7} //Reemplazar los numeros cuando esten instalados los leds | |
int puntaje = 0; | |
int posLed = 0; //Estas dos variables se comparan para ver si | |
int posPuntajeActual = 0; //hay que prender o no una led en ActualizarLeds | |
int botonA = ; //Igualar a la posicion del boton A (equipo A) | |
int botonB = ; //Igualar a la posicion del boton B (equipo B) | |
int botonC = ; //Igualar a la posicion del boton C (Reiniciar el juego) | |
void setup() { | |
StartGame(); | |
} | |
void loop() { | |
//Verificar si los botones fueron apretados este loop y actualizar puntaje | |
if (digitalRead(botonA) == HIGH) { puntaje++; } | |
if (digitalRead(botonB) == HIGH) { puntaje--; } | |
//Actualizar leds en base a puntaje | |
ActualizarLeds(puntaje); | |
//Reiniciar juego | |
if (digitalRead(botonC) == HIGH) { | |
StartGame(); | |
} | |
} | |
void StartGame() { | |
//Pone la puntuacion en 20 para arrancar el juego y prender leds | |
for (int i = 0; i < 4; i++){ | |
puntaje = puntaje + 5; | |
ActualizarLeds(puntaje); | |
} | |
} | |
void ActualizarLeds(int puntaje){ | |
//Calcular posicion a trabajar en base al puntaje actual | |
if (puntaje == 5) { | |
posPuntajeActual++; | |
puntaje = 0; | |
} | |
else { | |
if (puntaje == -5) { | |
posPuntajeActual--; | |
puntaje = 0; | |
} | |
} | |
//Verificar si hay que prender o apagar una luz | |
if (posPuntajeActual > posLed) { | |
digitalWrite(arreglo[posLed], HIGH); | |
posLed = posPuntajeActual; | |
//Verificar si es el fin del juego | |
if (posLed = 8){ | |
FinJuego(); | |
} | |
} | |
else { | |
if (posPuntajeActual < posLed) { | |
digitalWrite(arreglo[posLed], LOW); | |
posLed = posPuntajeActual; | |
//Verificar si es el fin del juego | |
if (posLed = -1){ | |
FinJuego(); | |
} | |
} | |
} | |
} | |
void FinJuego(){ | |
//Hacer sonar el buzzer | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment