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);
...
Read more »
There is nothing more profitable than making money online using an online casino. Don’t be lazy and go to the casino bonus offers at https://www.irishcasinohex.com/online-casinos/888 to discover a new hobby that will surely become your favorite, especially since this activity brings good passive income. which will not be useful to anyone.