Game 3 LEDs for Arduino

84

Posted in TechnologyArduino

Introduction: Game 3 LEDs for Arduino

This is the project of a game for arduino cresecente difficulties.

This is to repeat the sequence of the LEDs ignitions made by Arduino with the same colored buttons. For convenience I have also added a LCD to facilitate the conduct of the game.

ITALIANO

Questo è il progetto di un gioco per arduino di difficoltà cresecente.
Si tratta di ripetere la sequenza delle accensioni dei led presentata da arduino con i tasti dello stesso colore. Per comodità ho inserito anche un LCD per facilitare lo svolgimento del gioco.

Step 1: Materials

  • 1 Arduino Uno
  • 3 Led
  • 3 Buttons
  • Resistors
  • 1 Buzzer
  • 1 LCD

Step 2: Sketch

First I planned the random firing of 3 Led confirming the ignition with the sound of the buzzer

for (int x = 1; x < livello+3; x++) { // Accensione casuale 3 led e memorizzazione in variabile con array

rn = random(2, 5);

l1[x] = rn;

digitalWrite(rn, HIGH);

tone(ps, rn * 100, tempo - 100);

delay(tempo);

digitalWrite(rn, LOW);

delay(tempo); }

Then we have to wait for it to crush the buttons and store the result in another array.

clik = 1;
while (clik < livello+3) {

g = digitalRead(ppg);// pulsante giallo

if (g == HIGH) {

digitalWrite(plg, HIGH);

tone(ps, 200, tempo - 200);

delay(600);

digitalWrite(plg, LOW);

delay(600);

l1t[clik] = ppg-3; // memorizza il numero del pin del pulsante giallo sulla variabile l1t

clik++;

} r = digitalRead(ppr);// pulsante rosso

if (r == HIGH) {

digitalWrite(plr, HIGH);

tone(ps, 300, tempo - 200);

delay(600);

digitalWrite(plr, LOW);

delay(600);

l1t[clik] = ppr-3;

clik++;

}

b = digitalRead(ppb); //pulsante bianco

if (b == HIGH) {

digitalWrite(plb, HIGH);

tone(ps, 400, tempo - 200);

delay(600);

digitalWrite(plb, LOW);

delay(600);

l1t[clik] = ppb-3;

clik++;

}

Step 3: Sketch

Finally, we must compare the two variables that we created l1 and L1T if they are equal we move on to the next level otherwise you start over.

int vittoria = 0;
for (int x = 1; x < livello+3; x++) { // verifica

if(l1t[x]==l1[x]) // se i numeri dei pulsanti coincidono con quelli dei led continuo

vittoria++;

}

if (vittoria==livello+2){

Serial.println("bravissimo"); // vittoria

Serial.println(livello);

lcd.clear();

lcd.setCursor(1,0);

lcd.print("Bravo Continua ");

tone(ps, 800, 1000);

digitalWrite(plb,HIGH);

delay(1000);

digitalWrite(plb,LOW);

delay(1000);

); lcd.print("Ricomincia da 0");

livello=0;

tone(ps, 100, 2000);

} }

Step 4: Conclusion

The game is cute sufficiently result could better treat the appearance choreographed using more LCD.

Share

    Recommendations

    • Spotless Contest

      Spotless Contest
    • Space Challenge

      Space Challenge
    • Science of Cooking

      Science of Cooking
    user

    We have a be nice policy.
    Please be positive and constructive.

    Tips

    Questions

    Comments