10 x LEDs
11 x 330 Ohm resistencias
1 x resistencia de ohmio 10 k
1 x botón
1 x interruptor
1 x timbre
19 x Jumper cables
1 x placa o Perfboard
1 x Arduino Mega 2560 o Arduino Uno
Esto tomó mi amigo yo y un par de horas porque escribimos el código nosotros mismos. Sin embargo, si utiliza el código siguiente después de sólo le llevará unos 30 minutos a una hora.
Este es el código que he utilizado:
#include "pitches.h"
melodía de int [] = {}
NOTE_C4, NOTE_C3, NOTE_C5};
instanciación de inicialización de variables
led11 int = 4;
led12 int = 5;
int led13 = 6;
led14 int = 7;
int led21 = 8;
led22 int = 9;
led23 int = 10;
led24 int = 11;
int ledJackpot1 = 3;
int ledJackpot2 = 12;
int pushButtonPin = 2;
int pushSwitchPin = 40;
zumbador de int = 42;
int buttonState;
largo rand1;
largo rand2;
largo rand3;
se ejecuta cuando se presiona reset, sólo una vez
void setup() {}
pinMode(led11,OUTPUT);
pinMode(led12,OUTPUT);
pinMode(led13,OUTPUT);
pinMode(led14,OUTPUT);
pinMode(led21,OUTPUT);
pinMode(led22,OUTPUT);
pinMode(led23,OUTPUT);
pinMode(led24,OUTPUT);
pinMode(ledJackpot1,OUTPUT);
pinMode(ledJackpot2,OUTPUT);
pinMode(buzzer,OUTPUT);
pinMode (pushButtonPin, entrada);
pinMode (pushSwitchPin, entrada);
randomSeed(analogRead(0));
}
la función principal. se ejecuta infinitamente o hasta salir por usuario
void loop()
{
obtener el estado del botón
buttonState = digitalRead(pushButtonPin);
if(buttonState == High) {}
Si (digitalRead(pushSwitchPin) == HIGH) {rand1 = random(1,10);} else {rand1 = random(1,5);} //new línea
rand1 = random(1,10); Esto fue nuestra línea vieja
rand2 = random(1,5);
{Switch(rand1)}
caso 1: Si (digitalRead(led11) == LOW) {digitalWrite(led11,HIGH);} else {alreadyOut(1);} break;
caso 2: Si (digitalRead(led12) == LOW) {digitalWrite(led12,HIGH);} else {alreadyOut(1);} break;
caso 3: Si (digitalRead(led13) == LOW) {digitalWrite(led13,HIGH);} else {alreadyOut(1);} break;
caso 4: Si (digitalRead(led14) == LOW) {digitalWrite(led14,HIGH);} else {alreadyOut(1);} break;
caso 5: Si (digitalRead(led11) == LOW) {digitalWrite(led11,HIGH);} else {alreadyOut(1);} break;
caso 6: Si (digitalRead(led12) == LOW) {digitalWrite(led12,HIGH);} else {alreadyOut(1);} break;
caso 7: Si (digitalRead(led13) == LOW) {digitalWrite(led13,HIGH);} else {alreadyOut(1);} break;
caso 8: Si (digitalRead(led14) == LOW) {digitalWrite(led14,HIGH);} else {alreadyOut(1);} break;
caso 9: digitalWrite(led21,HIGH);
digitalWrite(led22,HIGH);
digitalWrite(led23,HIGH);
digitalWrite(led24,HIGH);
digitalWrite(led11,HIGH);
digitalWrite(led12,HIGH);
digitalWrite(led13,HIGH);
digitalWrite(led14,HIGH);
Jackpot();
rotura;
default: break;
}
{Switch(rand2)}
caso 1: Si (digitalRead(led21) == LOW) {digitalWrite(led21,HIGH);} else {alreadyOut(2);} break;
caso 2: Si (digitalRead(led22) == LOW) {digitalWrite(led22,HIGH);} else {alreadyOut(2);} break;
caso 3: Si (digitalRead(led23) == LOW) {digitalWrite(led23,HIGH);} else {alreadyOut(2);} break;
caso 4: Si (digitalRead(led24) == LOW) {digitalWrite(led24,HIGH);} else {alreadyOut(2);} break;
default: break;
}
Delay(300);
}
}
parpadea el LED verde para indicar jackpot
void jackpot()
{
mientras {}
digitalWrite(ledJackpot1,HIGH);
digitalWrite(ledJackpot2,LOW);
tono (42, melody[0],125);
Delay(100);
digitalWrite(ledJackpot1,LOW);
digitalWrite(ledJackpot2,HIGH);
tono (42, melody[1],125);
Delay(100);
}
}
void alreadyOut(int team)
{
if(Team == 1)
{
int nop = 4;
if(digitalRead(led11) == HIGH)
NOP-= 1;
if(digitalRead(led12) == HIGH)
NOP-= 1;
if(digitalRead(led13) == HIGH)
NOP-= 1;
if(digitalRead(led14) == HIGH)
NOP-= 1;
{Switch(NOP)}
caso 0: Si (digitalRead(pushSwitchPin) == HIGH) {jackpot();} else {break;}
caso 1: digitalWrite(led11,HIGH);
digitalWrite(led12,HIGH);
digitalWrite(led13,HIGH);
digitalWrite(led14,HIGH);
rotura;
caso 2: rand3 = random(1,3);
if(digitalRead(led11) == HIGH)
{
if(digitalRead(led12) == HIGH)
{
if(rand3 == 1) {}
digitalWrite(led13,HIGH); }
Else {}
digitalWrite(led14,HIGH); }
}
if(digitalRead(led13) == HIGH)
{
if(rand3 == 1) {}
digitalWrite(led12,HIGH); }
Else {}
digitalWrite(led14,HIGH); }
}
if(digitalRead(led14) == HIGH)
{
if(rand3 == 1) {}
digitalWrite(led12,HIGH); }
Else {}
digitalWrite(led13,HIGH); }
}
}
if(digitalRead(led12) == HIGH)
{
if(digitalRead(led13) == HIGH)
{
if(rand3 == 1) {}
digitalWrite(led11,HIGH); }
Else {}
digitalWrite(led14,HIGH); }
}
if(digitalRead(led14) == HIGH)
{
if(rand3 == 1) {}
digitalWrite(led11,HIGH); }
Else {}
digitalWrite(led13,HIGH); }
}
}
rotura;
caso 3: rand3 = random(1,4);
if(digitalRead(led11) == HIGH)
{
if(rand3 == 1) {}
digitalWrite(led12,HIGH); }
if(rand3 == 2) {}
digitalWrite(led13,HIGH); }
if(rand3 == 3) {}
digitalWrite(led14,HIGH);}
}
if(digitalRead(led12) == HIGH)
{
if(rand3 == 1) {}
digitalWrite(led11,HIGH); }
if(rand3 == 2) {}
digitalWrite(led13,HIGH); }
if(rand3 == 3) {}
digitalWrite(led14,HIGH);}
}
if(digitalRead(led13) == HIGH)
{
if(rand3 == 1) {}
digitalWrite(led11,HIGH); }
if(rand3 == 2) {}
digitalWrite(led12,HIGH); }
if(rand3 == 3) {}
digitalWrite(led14,HIGH); }
}
if(digitalRead(led14) == HIGH)
{
if(rand3 == 1) {}
digitalWrite(led11,HIGH); }
if(rand3 == 2) {}
digitalWrite(led12,HIGH); }
if(rand3 == 3) {}
digitalWrite(led13,HIGH); }
}
rotura;
}
} else
{
equipo 2
int nop = 4;
if(digitalRead(led21) == HIGH)
NOP-= 1;
if(digitalRead(led22) == HIGH)
NOP-= 1;
if(digitalRead(led23) == HIGH)
NOP-= 1;
if(digitalRead(led24) == HIGH)
NOP-= 1;
{Switch(NOP)}
caso 0: Si (digitalRead(pushSwitchPin) == HIGH) {jackpot();} else {break;}
caso 1: digitalWrite(led21,HIGH);
digitalWrite(led22,HIGH);
digitalWrite(led23,HIGH);
digitalWrite(led24,HIGH);
rotura;
caso 2: rand3 = random(1,3);
if(digitalRead(led21) == HIGH)
{
if(digitalRead(led22) == HIGH)
{
if(rand3 == 1)
digitalWrite(led23,HIGH);
otra cosa
digitalWrite(led24,HIGH);
}
if(digitalRead(led23) == HIGH)
{
if(rand3 == 1)
digitalWrite(led22,HIGH);
otra cosa
digitalWrite(led24,HIGH);
}
if(digitalRead(led24) == HIGH)
{
if(rand3 == 1)
digitalWrite(led22,HIGH);
otra cosa
digitalWrite(led23,HIGH);
}
}
if(digitalRead(led22) == HIGH)
{
if(digitalRead(led23) == HIGH)
{
if(rand3 == 1)
digitalWrite(led21,HIGH);
otra cosa
digitalWrite(led24,HIGH);
}
if(digitalRead(led24) == HIGH)
{
if(rand3 == 1)
digitalWrite(led21,HIGH);
otra cosa
digitalWrite(led23,HIGH);
}
}
rotura;
caso 3: rand3 = random(1,4);
if(digitalRead(led21) == HIGH)
{
if(rand3 == 1)
digitalWrite(led22,HIGH);
if(rand3 == 2)
digitalWrite(led23,HIGH);
if(rand3 == 3)
digitalWrite(led24,HIGH);
}
if(digitalRead(led22) == HIGH)
{
if(rand3 == 1)
digitalWrite(led21,HIGH);
if(rand3 == 2)
digitalWrite(led23,HIGH);
if(rand3 == 3)
digitalWrite(led24,HIGH);
}
if(digitalRead(led23) == HIGH)
{
if(rand3 == 1)
digitalWrite(led21,HIGH);
if(rand3 == 2)
digitalWrite(led22,HIGH);
if(rand3 == 3)
digitalWrite(led24,HIGH);
}
if(digitalRead(led24) == HIGH)
{
if(rand3 == 1)
digitalWrite(led21,HIGH);
if(rand3 == 2)
digitalWrite(led22,HIGH);
if(rand3 == 3)
digitalWrite(led23,HIGH);
}
rotura;
}
}
}