Skip to content

Instantly share code, notes, and snippets.

@ltuozzo
Created June 1, 2017 21:27
Show Gist options
  • Save ltuozzo/41a7f4cef6a7c581b17ae6e5c13ea8d8 to your computer and use it in GitHub Desktop.
Save ltuozzo/41a7f4cef6a7c581b17ae6e5c13ea8d8 to your computer and use it in GitHub Desktop.
int led[8] = {5,6,8,13,12,11,10,9}; //Reemplazar los numeros cuando esten instalados los leds
int puntaje = 0;
int punto = 2;
int puntajeStart = 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 = 7; //Igualar a la posicion del boton A (equipo A)
int botonB = 2; //Igualar a la posicion del boton B (equipo B)
int botonC = 4; //Igualar a la posicion del boton C (Reiniciar el juego)
int pin = 0;
void setup() {
//StartGame();
for ( int pinl=0; pinl< 8; pinl++){
pinMode (led[pinl], OUTPUT);
}
pinMode(botonA, INPUT);
pinMode(botonB, INPUT);
pinMode(botonC,INPUT);
}
void loop() {
//Verificar si los botones fueron apretados este loop y actualizar puntaje
/*if (digitalRead(botonA) == HIGH) { puntaje++; }
if (digitalRead(botonB) == HIGH) { puntaje--; }*/
if (digitalRead(botonA) == HIGH) {
puntaje++;
delay(250);
}
if (digitalRead(botonB) == HIGH) {
puntaje--;
delay(250);
}
//Actualizar leds en base a puntaje
//ActualizarLeds(puntaje);
//Reiniciar 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++){
int puntaje = puntaje + punto;
ActualizarLeds(puntaje);
puntaje = 0;
delay(100);
}
}
if (puntaje == punto) {
digitalWrite(led[pin], HIGH);
pin++;
puntaje = 0;
}
else {
if (puntaje == -punto){
pin--;
digitalWrite(led[pin], LOW);
puntaje = 0;
}
}
if (puntaje == punto || puntaje == -punto){
puntaje = 0;
}
}
void ActualizarLeds(int puntaje){
if (puntaje == punto) {
digitalWrite(led[pin], HIGH);
pin++;
}
else {
if (puntaje == -punto){
pin--;
digitalWrite(led[pin], LOW);
}
}
}
/*
void StartGame() {
//Pone la puntuacion en 20 para arrancar el juego y prender leds
for (int i = 0; i < puntaje; i++){
digitalWrite(led[i], LOW);
delay(100);
}
for (int i = 0; i < 4; i++){
int puntajeStart = puntajeStart + punto;
ActualizarLeds(puntajeStart);
puntajeStart = 0;
delay(100);
}
}*/
/*
void ActualizarLeds(int puntaje){
//Calcular posicion a trabajar en base al puntaje actual
if (puntaje == punto) {
posPuntajeActual++;
puntaje = 0;
}
else {
if (puntaje == -punto) {
posPuntajeActual--;
puntaje = 0;
}
}
//Verificar si hay que prender o apagar una luz
if (posPuntajeActual > posLed) {
digitalWrite(led[posLed], HIGH);
delay(250);
posLed = posPuntajeActual;
//Verificar si es el fin del juego
if (posLed = 8){
FinJuego();
}
}
else {
if (posPuntajeActual < posLed) {
digitalWrite(led[posLed], LOW);
delay(250);
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