Today we will learn to design a shield for arduino UNO, this shield is the famous game SIMON DICE is a very fun memory game for the family

GERBER PCB:

https://mega.nz/file/GBgUXAJD#USViaT9-u0ftuKR6a5rzWzX-M0PxRe-5M4HhbMKzSVI

SCHEMATIC DIAGRAM

In this schematic diagram we will observe the connections to the ARDUINO UNO pins.

FUNCTIONING

The operation is very easy to learn since the game will start giving us a led light either red, yellow, blue or green in color and in this case each led comes with a button so that we follow the sequence that the led diodes mark us, then like this We begin to memorize the sequence when we fail, the game will restart automatically and the buzzer will send us a beep saying that the game is over because we failed very easily, no.

ARDUINO CODE

#define   Rojo         2
#define   Verde        3
#define   Amarillo     4
#define   Azul         5
#define   Campana      7
#define   In_Rojo      A3
#define   In_Amarillo   A1
#define   In_Verde  A2
#define   In_Azul      A0
int i;
int nivelActual = 1;
int velocidad = 500;
const int MaximiNivel = 50;
int secuencia[MaximiNivel];
int SecuenciaLeida[MaximiNivel];

void setup(){
   pinMode(Amarillo, OUTPUT);
   pinMode(Azul, OUTPUT);
   pinMode(Rojo, OUTPUT);
   pinMode(Verde, OUTPUT);
   inicio();
}

void loop(){
   if(nivelActual == 1){
      generaSecuencia();
      muestraSecuencia();
      leeSecuencia();
   }
   if(nivelActual != 1){
      muestraSecuencia();
      leeSecuencia();
   }
}
// ------------------------  ------------------------
void inicio(){
  
 for (i = 1; i <= 6; i++) {
   digitalWrite(Verde , HIGH);
   delay(100);
   digitalWrite(Verde , LOW);
   digitalWrite(Amarillo , HIGH);
   delay(100);
   digitalWrite(Amarillo, LOW);
   digitalWrite(Azul , HIGH);
   delay(100);
   digitalWrite(Azul, LOW);
   digitalWrite(Rojo , HIGH);
   delay(100);
   digitalWrite(Rojo , LOW);
 } 
}

void Marcador(){
   int unidad = (nivelActual / 4);      
   imp_unidad(unidad);
   int residuo = (nivelActual % 4);
   imp_residuo(residuo);
   delay(500);
}

void imp_unidad(int n){
  for(int x=1;x<=n;x++){
   digitalWrite(Verde ,   1);  
   digitalWrite(Amarillo, 1);
   digitalWrite(Azul,     1);
   digitalWrite(Rojo ,    1);
   delay(800);
   apagados();
   delay(300);  
  }
}

void imp_residuo(int n){
  apagados();
  if (n==1){
   digitalWrite(Verde ,   1);  
  }
  if (n==2){
   digitalWrite(Verde ,   1); 
   digitalWrite(Amarillo, 1); 
  }
  if (n==3){
   digitalWrite(Verde ,   1);
   digitalWrite(Amarillo, 1);
   digitalWrite(Azul,     1);  
  } 
   delay(800);
   apagados();
   delay(300);  
}

void apagados(){
   digitalWrite(Verde ,   LOW);  
   digitalWrite(Amarillo, LOW);
   digitalWrite(Azul,     LOW);
   digitalWrite(Rojo ,    LOW);
   delay(300);
}

// -------------------   ---------------   -------

void muestraSecuencia(){
   apagados();
   for(int i = 0; i < nivelActual; i++){
      if( secuencia[i] == Amarillo ){
         tone(Campana, 200);
         delay(200);
         noTone(Campana);
      }
      if( secuencia[i] == Azul ){
         tone(Campana, 300);
         delay(200);
         noTone(Campana);
      }
      if( secuencia[i] == Rojo ){
         tone(Campana, 400);
         delay(200);
         noTone(Campana);
      }
      if( secuencia[i] == Verde ){
         tone(Campana, 500);
         delay(200);
         noTone(Campana);
      }
      digitalWrite(secuencia[i], HIGH);
      delay(velocidad);
      digitalWrite(secuencia[i], LOW);
      delay(200);
   }
}

void leeSecuencia(){
   int flag = 0;
   for(int i = 0; i < nivelActual; i++){
      flag = 0;
      while(flag == 0){
         if(digitalRead(In_Verde) == LOW){
            digitalWrite(Verde, HIGH);
            tone(Campana, 500);
            delay(300);
            noTone(Campana);
            SecuenciaLeida[i] = Verde;
            flag = 1;
            delay(200);
            if(SecuenciaLeida[i] != secuencia[i]){
               secuenciaError();
               return;
            }
            digitalWrite(Verde, LOW);
         }
         if(digitalRead(In_Rojo) == LOW){
            digitalWrite(Rojo, HIGH);
            tone(Campana, 400);
            delay(300);
            noTone(Campana);
            SecuenciaLeida[i] = Rojo;
            flag = 1;
            delay(200);
            if(SecuenciaLeida[i] != secuencia[i]){
               secuenciaError();
               return;
            }
            digitalWrite(Rojo, LOW);
         }
         if(digitalRead(In_Azul) == LOW){
            digitalWrite(Azul, HIGH);
            tone(Campana, 300);
            delay(300);
            noTone(Campana);
            SecuenciaLeida[i] = Azul;
            flag = 1;
            delay(200);
            if(SecuenciaLeida[i] != secuencia[i]){
               secuenciaError();
               return;
            }
            digitalWrite(Azul, LOW);
         }
         if(digitalRead(In_Amarillo) == LOW){
            digitalWrite(Amarillo, HIGH);
            tone(Campana, 200);
            delay(300);
            noTone(Campana);
            SecuenciaLeida[i] = Amarillo;
            flag = 1;
            delay(200);
            if(SecuenciaLeida[i] != secuencia[i]){
               secuenciaError();
               return;
            }
            digitalWrite(Amarillo, LOW);
         }
      }
   }
   secuenciaCorrecta();
}

void generaSecuencia(){
   randomSeed(analogRead(5));   // randomSeed(millis());
   for(int i = 0; i < MaximiNivel; i++){
      secuencia[i] = random(2,6);
   }
}

void TonoError(){
   int Tono[ ] = {260, 200, 200, 220, 200, 0, 250, 260};
   int duracionNotas[] = {4, 8, 8, 4, 4, 4, 4, 4};
   for(int i = 0; i < 8; i++){
      int duracionNota = 1000/duracionNotas[i];
      tone(Campana, Tono[i],duracionNotas);
      int pausaEntreNotas = duracionNota * 1.30;
      delay(pausaEntreNotas);
      noTone(Campana);
   }
}

void secuenciaError(){
   digitalWrite(Amarillo, HIGH);
   digitalWrite(Azul, HIGH);
   digitalWrite(Rojo, HIGH);
   digitalWrite(Verde, HIGH);
   delay(400);
   digitalWrite(Amarillo, LOW);
   digitalWrite(Azul, LOW);
   digitalWrite(Rojo, LOW);
   digitalWrite(Verde, LOW);
   delay(250);
   TonoError();
   velocidad = 500;
   Marcador();
   nivelActual = 1;
   inicio();
}

void secuenciaCorrecta(){
   if(nivelActual < MaximiNivel);
      nivelActual++;
    //velocidad -= 30;  // desmacar para aumentar velocidad del juego en cada nivel
   delay(350);
}

ELECTRONIC COMPONENTS

- 4 PULSADORES  NO 2 PIN

- 4 DIODOS LEDS 5MM RED  YELLOW GREEN BLUE

- 4 RESISTENCIAS 220ohm 1/4W

- 4 RESISTENCIAS 10K 1/4W

- 1 ESPADIN  20 PINES

- 1PCB

CHARACTERISTICS:

-VIN 5VDC
- SHIELD FOR ARDUINO UNO
- MEMORY GAME
- 4 BUTTONS NO
- RECREATIONAL GAME

- IMAX 50mA

EASYEDA

We can see the tracks and the 3D image that we made in the EASYEDA software, a very friendly software for the creation of PCBs.

JLCPCB

Once the pcb is designed, we will send our friends from JLCPCB to manufacture our PCB.

https://jlcpcb.com/RAV

5pcbs only $2

JLCPCB number 1 PCB manufacturing company worldwide professional pcbs and excellent finish.

GERBER PCB:

https://mega.nz/file/GBgUXAJD#USViaT9-u0ftuKR6a5rzWzX-M0PxRe-5M4HhbMKzSVI

you can get your pcbs in different sizes and colors.