10 x LEDs
11 x 330 Ohm weerstanden
1 x 10 k Ohm weerstand
1 x knop
1 x schakelaar
1 x Buzzer
19 x Jumper draden
1 x Breadboard of Perfboard
1 x Arduino Mega 2560 of Arduino Uno
Dit nam me en mijn vriend een paar uur omdat we de code zelf schreef. Maar als u de onderstaande code gebruiken, dan het alleen u ongeveer 30 minuten tot een uur nemen moet.
Dit is de code die ik gebruikt:
#include "pitches.h"
int melodie [] {} =
NOTE_C4, NOTE_C3, NOTE_C5};
variabele initialisatie/instantiëren
int led11 = 4;
int led12 = 5;
int led13 = 6;
int led14 = 7;
int led21 = 8;
int led22 = 9;
int led23 = 10;
int led24 = 11;
int ledJackpot1 = 3;
int ledJackpot2 = 12;
int pushButtonPin = 2;
int pushSwitchPin = 40;
int zoemer = 42;
int buttonState;
lange rand1;
lange rand2;
lange rand3;
wordt uitgevoerd w anneer reset wordt ingedrukt, eenmalig
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, INPUT);
pinMode (pushSwitchPin, INPUT);
randomSeed(analogRead(0));
}
de belangrijkste functie. draait oneindig of tot stoppen door gebruiker
void loop
{
krijgen van de toestand van de knop
buttonState = digitalRead(pushButtonPin);
if(buttonState == High) {}
Als (digitalRead(pushSwitchPin) == HIGH) {rand1 = random(1,10);} else {rand1 = random(1,5);} //new lijn
rand1 = random(1,10); Dit was onze oude lijn
rand2 = random(1,5);
switch(rand1) {}
geval 1: als (digitalRead(led11) == LOW) {digitalWrite(led11,HIGH);} else {alreadyOut(1);} breken;
geval 2: als (digitalRead(led12) == LOW) {digitalWrite(led12,HIGH);} else {alreadyOut(1);} breken;
Case 3: als (digitalRead(led13) == LOW) {digitalWrite(led13,HIGH);} else {alreadyOut(1);} breken;
geval 4: als (digitalRead(led14) == LOW) {digitalWrite(led14,HIGH);} else {alreadyOut(1);} breken;
geval 5: als (digitalRead(led11) == LOW) {digitalWrite(led11,HIGH);} else {alreadyOut(1);} breken;
kast 6: als (digitalRead(led12) == LOW) {digitalWrite(led12,HIGH);} else {alreadyOut(1);} breken;
geval 7: als (digitalRead(led13) == LOW) {digitalWrite(led13,HIGH);} else {alreadyOut(1);} breken;
geval 8: als (digitalRead(led14) == LOW) {digitalWrite(led14,HIGH);} else {alreadyOut(1);} breken;
zaak 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();
breken;
standaard: breken;
}
switch(rand2) {}
geval 1: als (digitalRead(led21) == LOW) {digitalWrite(led21,HIGH);} else {alreadyOut(2);} breken;
geval 2: als (digitalRead(led22) == LOW) {digitalWrite(led22,HIGH);} else {alreadyOut(2);} breken;
Case 3: als (digitalRead(led23) == LOW) {digitalWrite(led23,HIGH);} else {alreadyOut(2);} breken;
geval 4: als (digitalRead(led24) == LOW) {digitalWrite(led24,HIGH);} else {alreadyOut(2);} breken;
standaard: breken;
}
delay(300);
}
}
knippert de groene LED's om te betekenen van jackpot
VOID jackpot()
{
while (true) {}
digitalWrite(ledJackpot1,HIGH);
digitalWrite(ledJackpot2,LOW);
Toon (42, melody[0],125);
delay(100);
digitalWrite(ledJackpot1,LOW);
digitalWrite(ledJackpot2,HIGH);
Toon (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) {}
geval van 0: als (digitalRead(pushSwitchPin) == HIGH) {jackpot();} else {pauze;}
geval 1: digitalWrite(led11,HIGH);
digitalWrite(led12,HIGH);
digitalWrite(led13,HIGH);
digitalWrite(led14,HIGH);
breken;
geval 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); }
}
}
breken;
Case 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); }
}
breken;
}
} else
{
team 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) {}
geval van 0: als (digitalRead(pushSwitchPin) == HIGH) {jackpot();} else {pauze;}
geval 1: digitalWrite(led21,HIGH);
digitalWrite(led22,HIGH);
digitalWrite(led23,HIGH);
digitalWrite(led24,HIGH);
breken;
geval 2: rand3 = random(1,3);
if(digitalRead(led21) == HIGH)
{
if(digitalRead(led22) == HIGH)
{
if(rand3 == 1)
digitalWrite(led23,HIGH);
anders
digitalWrite(led24,HIGH);
}
if(digitalRead(led23) == HIGH)
{
if(rand3 == 1)
digitalWrite(led22,HIGH);
anders
digitalWrite(led24,HIGH);
}
if(digitalRead(led24) == HIGH)
{
if(rand3 == 1)
digitalWrite(led22,HIGH);
anders
digitalWrite(led23,HIGH);
}
}
if(digitalRead(led22) == HIGH)
{
if(digitalRead(led23) == HIGH)
{
if(rand3 == 1)
digitalWrite(led21,HIGH);
anders
digitalWrite(led24,HIGH);
}
if(digitalRead(led24) == HIGH)
{
if(rand3 == 1)
digitalWrite(led21,HIGH);
anders
digitalWrite(led23,HIGH);
}
}
breken;
Case 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);
}
breken;
}
}
}