Introduction: Smart Board Game

For a school project i and a fellow student are making a smart game. We both are making different parts of the smart boardgame. I will make the main game unit. He wil make the somewhat complicated minigames. The game is fully functional without the DLC made by the other student but it makes the game more fun. These devices can connect together to make one big game.

His instructable can be found here

The aim of the game is to collect all 6 parts that you can earn by doing various minigames. The player that has collected all six parts the first wins, One part is given for free when you pass start the first time.

The follow Moscow list is the moscow list of things that wil be made in this instructable:

MoSCoW

Must have: Gamecontroller

Should have: Buzz wire, Simon says

Could have: Color finder

Won’t have:

The main game

The Game wil exist out of 1 main game unit. With the playing field on top. And an lcd displaying the scores and usefull game information. There will be some buttons for sellecting things.

The minigames will be located at the corners of the game unit. As already said we will build the entire unit including all of the games, If you only want to build the unit without the DLC games you will have to do some modifications to the lasercutting plans because they are made for the entire unit.

Simon says

This game is simon says. I dont think that i need to explain what this game does since its very known. The game wil consist of 4 rounds of simon says. After that the game wil stop and you have won, when you win you will gain a part. Everytime you fail you lose a life. if you fail 3 times the game ends.

For this game i dont need a lot. Just a few buttons and a few leds and resistors.

Buzz wire

This game is Buzz wire. The sketch kinda gives away what the game is. Its a wire that you need to trace but cannot touch. If you touch the wire you lose a life. If you lose three lives you have lost the minigame. Then you won't gain a part for that game and you will have to try again.

For this game i bassically dont need sensors. I can just read out the current from the wires toutching on the arduino right away. The only thing i need is a buzzer for the buzz if you fail and a LED to indicate a hit.

An important thing to note before we begin, If you are planning on keeping the gameunit intact and you will use it frequently i suggest you solder the wire instead of using a breadboard. It was a pain in the ass to stop all the wires from disconnecting.

Step 1: Simon Says Module: What You Need

Now we are going to make the simon says module.

You need the following components for the module:

- (4) LED's
- (4) Resistors
- (1) Piezo speaker
- (4) buttons
- A bunch of wires
- A arduino

Furthermore you will need some sort of case to put it in. In this tutorial we will put the simon says module into the game module. If you only want the simon says module you can just put it in its own case.

The seconds picture is a sketch i made for a standalone unit. i only used it for developing the unit. The final simon says module is put into one case with the rest of the modules and is wired to the arduino mega.

Step 2: Simon Says Module: Building the Module - Step 1

In this first step we will place al the componets on the breadboard and hookup some simpel wires. You wil need to place the components as shown on the picture above. Try to space the buttons out a decent amount. this makes pressing the buttons easier.

Step 3: Simon Says Module: Building the Module - Step 2

In this step we hookup the led's to the arduino. Just connect the possitive legs from the led's to the 2/3/4/5 ports on the arduino. Then you can put the piezo speaker on the board and connect the positive pin to port 10.

Step 4: Simon Says Module: Building the Module - Step 3

Connect all the buttons to the negative line on the breadboard. Then connect the other pins of the buttons to the 6/7/8/9 ports on the arduino

Step 5: Simon Says Module: the Code

I did not make the sketch for simon says myself. The sketch was originally made by Robert Spann back in 2009. I am pretty lazy so i just got the sketch from mpilchfamily's instructables . To give the game sound it using the Tone.h Library. You will get an error if you dont install the Tone library, downlod the tone.zip and put it in the adruino library folder. A file of the sketch and Tone Library is also attached.

You can go to How to Install a Library to learn it.

The original Tutorial

Learn to install librarys

If you want to know how the simon says module works in depth i suggest you go check out the original tutorial, The creator explains it very well and i do not see the need to repeat his explenation.

Step 6: Simon Says Module - Adapting the Code

So now we have the code and it is working perfectly with the arduino on it's own, it is time to re-write the code so it can be used in the main game module. This step is pretty much the same for every module and if you do it this way you can very easily expand the game module until it runs out of ports (wich are a lot of ports on the arduino mega lol)

First we need to define the variables for the module in the main code i have commented everything so it stays readable.

I adapted the ports to the ports on the right sight on the board so the ports lined up better with the place of the simon says module on the board.

/Vars for Simon Says
#include Tone speakerpin; int starttune[] = {NOTE_C4, NOTE_F4, NOTE_C4, NOTE_F4, NOTE_C4, NOTE_F4, NOTE_C4, NOTE_F4, NOTE_G4, NOTE_F4, NOTE_E4, NOTE_F4, NOTE_G4}; int duration2[] = {100, 200, 100, 200, 100, 400, 100, 100, 100, 100, 200, 100, 500}; int note[] = {NOTE_C4, NOTE_C4, NOTE_G4, NOTE_C5, NOTE_G4, NOTE_C5}; int duration[] = {100, 100, 100, 300, 100, 300}; int button[] = {26, 27, 28, 29}; //Vier knop pins int ledpin[] = {22, 23, 24, 25}; // LED pins int turnss = 0; // turnss counter int buttonstate = 0; // button state checker int randomArray[100]; //Verschillende volgorde int inputArray[100];

Next follow the setup wich will be in the setup loop of the arduino this code is still the same exept for the speaker pin i moved that to better fit the position of the simon says module.

speakerpin.begin(30);

for (int i = 0; i < 4; i++) { pinMode(ledpin[i], OUTPUT); }

for (int i = 0; i < 4; i++) { pinMode(button[i], INPUT); digitalWrite(button[i], HIGH); }

randomSeed(analogRead(15)); //Added to generate "more randomness" with the randomArray for the output function for (int thisNote = 0; thisNote < 13; thisNote ++) { // play the next note: speakerpin.play(starttune[thisNote]); // hold the note: if (thisNote == 0 || thisNote == 2 || thisNote == 4 || thisNote == 6) { digitalWrite(ledpin[0], HIGH); } if (thisNote == 1 || thisNote == 3 || thisNote == 5 || thisNote == 7 || thisNote == 9 || thisNote == 11) { digitalWrite(ledpin[1], HIGH); } if (thisNote == 8 || thisNote == 12) { digitalWrite(ledpin[2], HIGH); } if (thisNote == 10) { digitalWrite(ledpin[3], HIGH); } delay(duration2[thisNote]); // stop for the next note: speakerpin.stop(); digitalWrite(ledpin[0], LOW); digitalWrite(ledpin[1], LOW); digitalWrite(ledpin[2], LOW); digitalWrite(ledpin[3], LOW); delay(25); } delay(1000); }

Since the main game unit controls al the games and the time they will be activated, All of the modules loop functions have been put into functions that are called based on what is happening in the main loop

////////////////////////////////////////////////////////////////////////
// // //Simon Says Functions // // // ////////////////////////////////////////////////////////////////////////

void SimonSays() {

//function for generating the array to be matched by the player

digitalWrite(ledpin[0], HIGH); digitalWrite(ledpin[1], HIGH); digitalWrite(ledpin[2], HIGH); digitalWrite(ledpin[3], HIGH);

for (int thisNote = 0; thisNote < 6; thisNote ++) { // play the next note: speakerpin.play(note[thisNote]); // hold the note: delay(duration[thisNote]); // stop for the next note: speakerpin.stop(); delay(25); }

digitalWrite(ledpin[0], LOW); digitalWrite(ledpin[1], LOW); digitalWrite(ledpin[2], LOW); digitalWrite(ledpin[3], LOW); delay(1000);

for (int y = turnss; y <= turnss; y++) { //Limited by the turnss variable Serial.println(""); //Some serial output to follow along Serial.print("Turn: "); Serial.print(y); Serial.println(""); randomArray[y] = random(1, 5); //Assigning a random number (1-4) to the randomArray[y], y being the turnss count for (int i = 0; i <= turnss; i++) { Serial.print(randomArray[i]);

for (int y = 0; y < 4; y++) {

if (randomArray[i] == 1 && ledpin[y] == 22) { //if statements to display the stored values in the array digitalWrite(ledpin[y], HIGH); speakerpin.play(NOTE_G3, 100); delay(400); digitalWrite(ledpin[y], LOW); delay(100); }

if (randomArray[i] == 2 && ledpin[y] == 23) { digitalWrite(ledpin[y], HIGH); speakerpin.play(NOTE_A3, 100); delay(400); digitalWrite(ledpin[y], LOW); delay(100); }

if (randomArray[i] == 3 && ledpin[y] == 24) { digitalWrite(ledpin[y], HIGH); speakerpin.play(NOTE_B3, 100); delay(400); digitalWrite(ledpin[y], LOW); delay(100); }

if (randomArray[i] == 4 && ledpin[y] == 25) { digitalWrite(ledpin[y], HIGH); speakerpin.play(NOTE_C4, 100); delay(400); digitalWrite(ledpin[y], LOW); delay(100); } } } }0 input();

}

void input() {

for (int i = 0; i <= turnss;) { for (int y = 0; y < 4; y++) {

buttonstate = digitalRead(button[y]);

if (buttonstate == LOW && button[y] == 26) { //Checking for button push digitalWrite(ledpin[0], HIGH); speakerpin.play(NOTE_G3, 100); delay(200); digitalWrite(ledpin[0], LOW); inputArray[i] = 1; delay(250); Serial.print(" "); Serial.print(1); if (inputArray[i] != randomArray[i]) { fail(); } i++; } if (buttonstate == LOW && button[y] == 27) { digitalWrite(ledpin[1], HIGH); speakerpin.play(NOTE_A3, 100); delay(200); digitalWrite(ledpin[1], LOW); inputArray[i] = 2; delay(250); Serial.print(" "); Serial.print(2); if (inputArray[i] != randomArray[i]) { fail(); } i++; }

if (buttonstate == LOW && button[y] == 28) { digitalWrite(ledpin[2], HIGH); speakerpin.play(NOTE_B3, 100); delay(200); digitalWrite(ledpin[2], LOW); inputArray[i] = 3; delay(250); Serial.print(" "); Serial.print(3); if (inputArray[i] != randomArray[i]) { fail(); } i++; }

if (buttonstate == LOW && button[y] == 29) { digitalWrite(ledpin[3], HIGH); speakerpin.play(NOTE_C4, 100); delay(200); digitalWrite(ledpin[3], LOW); inputArray[i] = 4; delay(250); Serial.print(" "); Serial.print(4); if (inputArray[i] != randomArray[i]) { fail(); } i++; } } } delay(500); turnss++; if (turnss == 4) { lives = 5; } }

void fail() {

for (int y = 0; y <= 2; y++) { //Flashes lights for failure

digitalWrite(ledpin[0], HIGH); digitalWrite(ledpin[1], HIGH); digitalWrite(ledpin[2], HIGH); digitalWrite(ledpin[3], HIGH); speakerpin.play(NOTE_G3, 300); delay(200); digitalWrite(ledpin[0], LOW); digitalWrite(ledpin[1], LOW); digitalWrite(ledpin[2], LOW); digitalWrite(ledpin[3], LOW); speakerpin.play(NOTE_C3, 300); delay(200); } delay(500); turnss--; lives--; Serial.println("Lives: " + String(lives)); }

The code above is still the same as the original simon says code. The only thing changed is that it is in his own function and if you fail the game will take away one of your lives. If you reach turn 4 and you win the game wil put your lives on 5. By setting your lives to 5 the main game recognises that the game is over and has been won by the player.

Step 7: BuzzWire Module: Building the Module - Step 1

Now we are making the buzzwire module. This module is pretty simple as you can see from the sketch. For this module you need the following things:

  • Piezo speaker
  • Led
  • A resistor
  • A long piece of copper wire
  • A shorter piece of copper wire
  • Some wires

Step 8: BuzzWire Module: Building the Module - Step 1

In the first step you will need to make the rod and the wire. I bended mine like the pictures above. It doesn't really matters how it looks. As long as it looks something like the pictures above. The you just need to solder a wire to the rod and a wire to the frame.

Step 9: BuzzWire Module: Building the Module - Step 2

Now you put the led and the piezo speaker on the breadboard. Put the resistor on the led and led the minus leg of the piezoe speaker go to the same row as the resistor creating a minus row. Put the minus wire of the frame into a random row

Step 10: BuzzWire Module: Building the Module - Step 3

Wire the positive led leg into port 2 on the arduino. The wire of the rod can go straight into 5 volts. The negative wire of the frame can go into port A0

Step 11: BuzzWire Module: the Code

The module should look something like this. If you want to create the full game module you can skip this step. The software for the full module will be a bit further in this instructable. If you want to build this module only you can keep on reading.

One thing very important to note is that the copper is very sensitive. It will pick up any electric field near by. Because of this the code has its if statement programmed for higher than 1000. Even like this the code is still very unstable, I suggest not playing this game while you have a lot of electrical equipment nearby for some reason it seems to pick up the electrical field from that equipment.

This is the code for the buzzwire module as a standalone:

int wireRodPin = A3;int wireFeedbackPin = 53;
int BuzzHit = 0;

void setup(){

pinMode(wireRodPin, INPUT);

pinMode(wireFeedbackPin, OUTPUT);

}

void loop() {
BuzzHit = analogRead(wireRodPin); if (BuzzHit > 1000) { digitalWrite(wireFeedbackPin, HIGH); delay(1500); digitalWrite(wireFeedbackPin, LOW); } else { digitalWrite(wireFeedbackPin, LOW); } currentButtonState = digitalRead(buttonGCPin); if (currentButtonState == HIGH && lastButtonState == LOW) { } lastButtonState = currentButtonState; }

The code for the BuzzWire module is a lot simpeler than the code for the simon says module. But the basics are the same. First we define the vars,

int wireRodPin = A3;
int wireFeedbackPin = 53; int BuzzHit = 0;

Than the setup:

pinMode(wireRodPin, INPUT);
pinMode(wireFeedbackPin, OUTPUT);

Than the game function that is called by the game loop:

////////////////////////////////////////////////////////////////////////
// // //BuzzWire Functions // // // ////////////////////////////////////////////////////////////////////////

void buzzwire() { BuzzHit = analogRead(wireRodPin);

if (BuzzHit > 1000) { digitalWrite(wireFeedbackPin, HIGH); delay(1500); digitalWrite(wireFeedbackPin, LOW); lives--; } else { digitalWrite(wireFeedbackPin, LOW); } currentButtonState = digitalRead(buttonGCPin); if (currentButtonState == HIGH && lastButtonState == LOW) { lives = 5; } lastButtonState = currentButtonState; }

As you can see the actual function is pretty simple. We basically only check if the rod touches the copper frame. If that happens you lose a life. If you make it you have to press a button and your lives will be set to 5, Than the game knows that the player has won.

There is a pretty good reason why we chose to make the win condition a button. We tried making it so that the end of the copperwire had a different wire atached if that would be touched with the rod you would win. Even tho the wires where not touching we could not get it to work. For some reason the two wires seamed to interfere with one another so we scraped that part and whent for a button.

Step 12: Main Game Module

Now that the lose game modules are done it is time for the main game module. Codewise is this the most difficult part of the entire project. The picture above is the main core of the game module it features a screen, 2 buttons and a potentiometer. When running the screens shows who's turn it is. If you press the right button you will get into the game menu. Here can you scroll between the different minigames. If you have found the minigame you want to play (The tile you landed on) you can select that minigame by pressing the left button. All of the feedback from the minigames regarding winning and losing are shown on this display.

Step 13: Main Game Module - Building the Module

This module is build right into the arduino mega. Because i did not see the point of making it on a arduino uno because it wont work.

The Requirements:

- A Arduino mega(You could use a uno but then you need to adapt the code a bit to your needs)
- 2 potentiometers

- 1 LCD Screen
- 2 buttons
- lots of wire
- If possible a ribbon cable (Saves a lot of hassle when mounting the screen into the module)
-2 resistors for the buttons.

For the layout just copy what i did on the picture above. The resistors and the seemingly lose hanging wires are for the buttons. I had already removed them from the breadboard the moment i made the picture so thats why there missing. Also the potentiometer on the left (I used a slide potentiometer) is for the contrast. The second potentiometer must be placed on the right on the 3 connections without the resistor.

The port connections are as the following:

Since this is the main game loop i connected all the things to the lower number ports on the arduino.

The screen is connected to the following ports: 7,6,5,4,3,2
The port for connecting the gamecontrol button is 10
The port for connecting the gameselect button is 11

Step 14: Main Game Module - Building the Module Step 2

The game module should look something like the above only with a ribbon cable between de breadboard and the screen if you used one.

Step 15: Main Game Module - Making the Code

This step i pretty big since it covers a lot of information regarding the programming of the main module. Here is a explanation what each part of the code does. If you do not feel the need to know the nitty gritty of the code you can skip ahead to the next step. The full code wil be featured there.

First we need to define all the variables.

//Vars for Gameloop
#include <LiquidCrystal.h>

int gameChooser = 0; int ChoosenGame = 0; LiquidCrystal lcd(7, 6, 5, 4, 3, 2); int buttonGCPin = 10; int buttonSelectPin = 11;

//Global vars int lives = 3; int TurnEnable = 1; int Turn = 0; boolean currentButtonState = LOW; boolean lastButtonState = LOW;

The vars include 2 sections the first section is all the variables used by the game selection part of the code. The second section are the variables used by various functions in the code.

After we have defined the variables we have the setup for the gameloop.

void setup() {
Serial.begin(9600); lcd.begin(16, 2);

//GameLoop setup
pinMode(buttonGCPin, INPUT); pinMode(buttonSelectPin, INPUT);

}

First of all we have the the serial begin. This is something that you no not need. It is in there for debugging purposes. You can check the feedback of the games in the serial monitor.

This is the loop that bassically controlls everything, The first two checks are for checking which players turn it is and printing that out. There is also a check to get into the button select menu. If the button is pressed the game chooser will be activated and the TurnEnable is deactivated. stopping the loop from printing out what players turn it is.

void loop() {
if (Turn == 0 && TurnEnable == 1) { lcd.setCursor(0, 0); lcd.print("Player 1's turn"); lcd.setCursor(0, 1); lcd.print("Waiting for game"); currentButtonState = digitalRead(buttonSelectPin); if (currentButtonState == HIGH && lastButtonState == LOW) { gameChooser = 1; TurnEnable = 0; lcd.clear(); } } if (Turn == 1 && TurnEnable == 1) { lcd.setCursor(0, 0); lcd.print("Player 2's turn"); lcd.setCursor(0, 1); lcd.print("Waiting for game"); currentButtonState = digitalRead(buttonSelectPin); if (currentButtonState == HIGH && lastButtonState == LOW) { gameChooser = 1; TurnEnable = 0; lcd.clear(); } }

if (gameChooser == 1) {
gamePicker(); }

}

If the game chooser button has been pressed the gamepicker function will be called. That is the following function:

void gamePicker() {
int sensorValue = analogRead(A0); //game kies menu if (sensorValue < 200) { lcd.setCursor(0, 0); // lcd.print(">Simon Says< "); lcd.setCursor(0, 1); lcd.print("WirePuller "); } else if (sensorValue > 200 && sensorValue < 400) { lcd.setCursor(0, 0); lcd.print(">WirePuller< "); lcd.setCursor(0, 1); lcd.print("BuzzWire "); } else if (sensorValue > 400 && sensorValue < 600) { lcd.setCursor(0, 0); lcd.print(">BuzzWire< "); lcd.setCursor(0, 1); lcd.print("NoiseDetector "); } else if (sensorValue > 600 && sensorValue < 800) { lcd.setCursor(0, 0); lcd.print(">NoiseDetector< "); lcd.setCursor(0, 1); lcd.print("Quiz "); } else if (sensorValue > 800) { lcd.setCursor(0, 0); lcd.print(">Quiz< "); lcd.setCursor(0, 1); lcd.print(" "); }

currentButtonState = digitalRead(buttonGCPin); if (currentButtonState == HIGH && lastButtonState == LOW && sensorValue < 200) { lcd.setCursor(0, 0); lcd.print("Starting: "); lcd.setCursor(0, 1); lcd.print("Simon Says "); delay(2000); lcd.clear(); ChoosenGame = 1; gameChooser = 0; } else if (currentButtonState == HIGH && lastButtonState == LOW && sensorValue > 200 && sensorValue < 400) { lcd.setCursor(0, 0); lcd.print("Starting: "); lcd.setCursor(0, 1); lcd.print("WirePuller "); delay(2000); lcd.clear(); ChoosenGame = 2; gameChooser = 0; } else if (currentButtonState == HIGH && lastButtonState == LOW && sensorValue > 400 && sensorValue < 600) { lcd.setCursor(0, 0); lcd.print("Starting: "); lcd.setCursor(0, 1); lcd.print("BuzzWire "); delay(2000); lcd.clear(); ChoosenGame = 3; gameChooser = 0; } else if (currentButtonState == HIGH && lastButtonState == LOW && sensorValue > 600 && sensorValue < 800) { lcd.setCursor(0, 0); lcd.print("Starting: "); lcd.setCursor(0, 1); lcd.print("NoiseDetector "); delay(2000); lcd.clear(); ChoosenGame = 4; gameChooser = 0; } else if (currentButtonState == HIGH && lastButtonState == LOW && sensorValue > 800) { lcd.setCursor(0, 0); lcd.print("Starting: "); lcd.setCursor(0, 1); lcd.print("Quiz "); delay(2000); lcd.clear(); ChoosenGame = 5; gameChooser = 0; } lastButtonState = currentButtonState; }

What this does is it controlls the scrolltrough menu of the games. In this menu you select one of the games

Than this is the part wich controlls all of the game mechanics. When a game is chosen it shows what game is being played. These gamecontrol loops also check if you won or lost a minigame. When you win a minigame the screen wil say player [number of player] gained a point. Indicating that you have earned the part of that game. A victory sound will be played and the turns will be switched. If you lose a game the screen will say Player [number of player] is gameover. A gameover sound will be played and the turn will be switched. This works the same way for all of the games.

void loop() {

lastButtonState = currentButtonState;

//Simon Says if (ChoosenGame == 1) { lcd.setCursor(0, 0); lcd.print("Playing:"); lcd.setCursor(0, 1); lcd.print("Simon Says"); if (lives == 0) { lcd.clear(); lcd.setCursor(0, 0); lcd.print("Player " + String(Turn + 1)); lcd.setCursor(0, 1); lcd.print("Is Gameover!"); failsound(); delay(2500); ChoosenGame = 0; turnss = 0; TurnSwitch(); } else if (lives == 5) { lcd.clear(); lcd.setCursor(0, 0); lcd.print("Player " + String(Turn + 1)); lcd.setCursor(0, 1); lcd.print("Gained a point!"); delay(2500); victorysound(); ChoosenGame = 0; turnss = 0; TurnSwitch(); } else { SimonSays(); } }

// WirePuller if (ChoosenGame == 2) { lcd.setCursor(0, 0); lcd.print("Playing:"); lcd.setCursor(0, 1); lcd.print("Wirepuller"); wirepuller(); if (lives == 0) { lcdquiz.clear(); lcd.clear(); lcd.setCursor(0, 0); lcd.print("Player " + String(Turn + 1)); lcd.setCursor(0, 1); lcd.print("Is Gameover!"); failsound(); delay(2500); ChoosenGame = 0; TurnSwitch(); } else if (lives == 5) { lcdquiz.clear(); lcd.clear(); lcd.setCursor(0, 0); lcd.print("Player " + String(Turn + 1)); lcd.setCursor(0, 1); lcd.print("Gained a point!"); delay(2500); victorysound(); ChoosenGame = 0; TurnSwitch(); } } //BuzzWire if (ChoosenGame == 3) { lcd.setCursor(0, 0); lcd.print("Playing:"); lcd.setCursor(0, 1); lcd.print("BuzzWire"); buzzwire(); if (lives == 0) { lcd.clear(); lcd.setCursor(0, 0); lcd.print("Player " + String(Turn + 1)); lcd.setCursor(0, 1); lcd.print("Is Gameover!"); failsound(); delay(2500); ChoosenGame = 0; TurnSwitch(); } else if (lives == 5) { lcd.clear(); lcd.setCursor(0, 0); lcd.print("Player " + String(Turn + 1)); lcd.setCursor(0, 1); lcd.print("Gained a point!"); delay(2500); victorysound(); ChoosenGame = 0; TurnSwitch(); } } //NoiseDetector if (ChoosenGame == 4) { lcd.setCursor(0, 0); lcd.print("Playing:"); lcd.setCursor(0, 1); lcd.print("Noisedetector"); noisedetector(); if (lives == 0) { lcd.clear(); lcd.setCursor(0, 0); lcd.print("Player " + String(Turn + 1)); lcd.setCursor(0, 1); lcd.print("Is Gameover!"); failsound(); delay(2500); ChoosenGame = 0; TurnSwitch(); } else if (lives == 5) { lcd.clear(); lcd.setCursor(0, 0); lcd.print("Player " + String(Turn + 1)); lcd.setCursor(0, 1); lcd.print("Gained a point!"); delay(2500); victorysound(); ChoosenGame = 0; TurnSwitch(); } } //Quiz if (ChoosenGame == 5) { quiz(); if (lives == 0) { lcd.clear(); lcdquiz.clear(); lcd.setCursor(0, 0); lcd.print("Player " + String(Turn + 1)); lcd.setCursor(0, 1); lcd.print("Is Gameover!"); failsound(); delay(2500); ChoosenGame = 0; TurnSwitch(); } else if (lives == 5) { lcd.clear(); lcdquiz.clear(); lcd.setCursor(0, 0); lcd.print("Player " + String(Turn + 1)); lcd.setCursor(0, 1); lcd.print("Gained a point!"); delay(2500); victorysound(); ChoosenGame = 0; TurnSwitch(); } } }

This is the loop that handles the turn switching. it is pretty straigt forward. if player one is playing it will be switched to player 2 and the lives will be reset. if player 2 is playing it will work the other way around.

void TurnSwitch() {
if (Turn == 0) { Turn = 1; TurnEnable = 1; lives = 3; } else if (Turn == 1) { Turn = 0; TurnEnable = 1; lives = 3; } }

This is the victory loop. This will be called when a game is won. It just plays a victory sound

void victorysound() {
for (int thisNote = 0; thisNote < 6; thisNote ++) { // play the next note: speakerpin.play(note[thisNote]); // hold the note: delay(duration[thisNote]); // stop for the next note: speakerpin.stop(); delay(25); } }

This is the gameover loop. This one is called when a game is lost. It just plays a gameover sound.

void failsound() {
for (int y = 0; y <= 2; y++) { speakerpin.play(NOTE_G3, 300); delay(200); speakerpin.play(NOTE_C3, 300); delay(200); } }

Step 16: Main Game Module - Combining the Code

Now that we have all the code we need for the game loop we can combine it all. I have got two versions of the combined code. One is with the dlc and one is withouth the DLC. The code is also attached as a download so you can also use that one. The code is ready to go if you use all of the ports the same way as we did. If you changed some of the ports arround check the vars in the code and change them if necessary.

The code without the DLC:

<p>//Vars for Gameloop<br3#include 

int gameChooser = 0;
int ChoosenGame = 0;
int Gamewin = 0;
int scoreP1 = 0;
int scoreP2 = 0;
int Turn = 0;
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
int buttonGCPin = 10;
int buttonSelectPin = 11;
int TurnEnable = 1;
boolean currentButtonState = LOW;
boolean lastButtonState = LOW;</p><p>//Vars for buzzwire
int wireRodPin = A3;
int wireFeedbackPin = 53;
int BuzzHit = 0;</p><p>//Vars for Simon Says
#include 
Tone speakerpin;</p><p>int starttune[] = {NOTE_C4, NOTE_F4, NOTE_C4, NOTE_F4, NOTE_C4, NOTE_F4, NOTE_C4, NOTE_F4, NOTE_G4, NOTE_F4, NOTE_E4, NOTE_F4, NOTE_G4};
int duration2[] = {100, 200, 100, 200, 100, 400, 100, 100, 100, 100, 200, 100, 500};
int note[] = {NOTE_C4, NOTE_C4, NOTE_G4, NOTE_C5, NOTE_G4, NOTE_C5};
int duration[] = {100, 100, 100, 300, 100, 300};
int button[] = {26, 27, 28, 29}; //Vier knop pins
int ledpin[] = {22, 23, 24, 25};  // LED pins
int turnss = 0;  // turnss counter
int buttonstate = 0;  // button state checker
int randomArray[100]; //Verschillende volgorde
int inputArray[100];</p><p>//Global vars
int lives = 3;</p><p>void setup() {
  Serial.begin(9600);
  lcd.begin(16, 2);</p><p>  //GameLoop setup
  pinMode(buttonGCPin, INPUT);
  pinMode(buttonSelectPin, INPUT);</p><p>  //Buzzwire setup
  pinMode(wireRodPin, INPUT);
  pinMode(wireFeedbackPin, OUTPUT);</p><p>  // Simon Says Setup
  speakerpin.begin(30); // speaker op pin 10</p><p>  for (int i = 0; i < 4; i++) {
    pinMode(ledpin[i], OUTPUT);
  }</p><p>  for (int i = 0; i < 4; i++) {
    pinMode(button[i], INPUT);
    digitalWrite(button[i], HIGH);
  }</p><p>  randomSeed(analogRead(15)); //Added to generate "more randomness" with the randomArray for the output function
  for (int thisNote = 0; thisNote < 13; thisNote ++) {
    // play the next note:
    speakerpin.play(starttune[thisNote]);
    // hold the note:
    if (thisNote == 0 || thisNote == 2 || thisNote == 4 || thisNote == 6)
    {
      digitalWrite(ledpin[0], HIGH);
    }
    if (thisNote == 1 || thisNote == 3 || thisNote == 5 || thisNote == 7 || thisNote == 9 || thisNote == 11)
    {
      digitalWrite(ledpin[1], HIGH);
    }
    if (thisNote == 8 || thisNote == 12)
    {
      digitalWrite(ledpin[2], HIGH);
    }
    if (thisNote == 10)
    {
      digitalWrite(ledpin[3], HIGH);
    }
    delay(duration2[thisNote]);
    // stop for the next note:
    speakerpin.stop();
    digitalWrite(ledpin[0], LOW);
    digitalWrite(ledpin[1], LOW);
    digitalWrite(ledpin[2], LOW);
    digitalWrite(ledpin[3], LOW);
    delay(25);
  }
  delay(1000);
}</p><p>void loop() {
  if (Turn == 0 && TurnEnable == 1) {
    lcd.setCursor(0, 0);
    lcd.print("Player 1's turn");
    lcd.setCursor(0, 1);
    lcd.print("Waiting for game");
    currentButtonState = digitalRead(buttonSelectPin);
    if (currentButtonState == HIGH && lastButtonState == LOW) {
      gameChooser = 1;
      TurnEnable = 0;
      lcd.clear();
    }
  }
  if (Turn == 1 && TurnEnable == 1) {
    lcd.setCursor(0, 0);
    lcd.print("Player 2's turn");
    lcd.setCursor(0, 1);
    lcd.print("Waiting for game");
    currentButtonState = digitalRead(buttonSelectPin);
    if (currentButtonState == HIGH && lastButtonState == LOW) {
      gameChooser = 1;
      TurnEnable = 0;
      lcd.clear();
    }
  }</p><p>  if (gameChooser == 1) {
    gamePicker();
  }
  lastButtonState = currentButtonState;</p><p>  //Simon Says
  if (ChoosenGame == 1) {
    lcd.setCursor(0, 0);
    lcd.print("Playing:");
    lcd.setCursor(0, 1);
    lcd.print("Simon Says");
    if (lives == 0) {
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("Player " + String(Turn + 1));
      lcd.setCursor(0, 1);
      lcd.print("Is Gameover!");
      failsound();
      delay(2500);
      ChoosenGame = 0;
      turnss = 0;
      TurnSwitch();
    } else if (lives == 5) {
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("Player " + String(Turn + 1));
      lcd.setCursor(0, 1);
      lcd.print("Gained a point!");
      delay(2500);
      victorysound();
      ChoosenGame = 0;
      turnss = 0;
      TurnSwitch();
    } else {
      SimonSays();
    }
  }</p><p>  
  //BuzzWire
  if (ChoosenGame == 2) {
    lcd.setCursor(0, 0);
    lcd.print("Playing:");
    lcd.setCursor(0, 1);
    lcd.print("BuzzWire");
    buzzwire();
    if (lives == 0) {
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("Player " + String(Turn + 1));
      lcd.setCursor(0, 1);
      lcd.print("Is Gameover!");
      failsound();
      delay(2500);
      ChoosenGame = 0;
      TurnSwitch();
    } else if (lives == 5) {
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("Player " + String(Turn + 1));
      lcd.setCursor(0, 1);
      lcd.print("Gained a point!");
      delay(2500);
      victorysound();
      ChoosenGame = 0;
      TurnSwitch();
    }
  }
 
}</p><p>////////////////////////////////////////////////////////////////////////
//                                                                    //
//Game  Functions                                                     //
//                                                                    //
////////////////////////////////////////////////////////////////////////</p><p>void TurnSwitch() {
  if (Turn == 0) {
    Turn = 1;
    TurnEnable = 1;
    lives = 3;
  } else if (Turn == 1) {
    Turn = 0;
    TurnEnable = 1;
    lives = 3;
  }
}</p><p>void gamePicker() {
  int sensorValue = analogRead(A0);
  //game kies menu
  if (sensorValue < 500) {
    lcd.setCursor(0, 0);       //
    lcd.print(">Simon Says<     ");
    lcd.setCursor(0, 1);
    lcd.print("BuzzWire        ");
  } else if (sensorValue > 500) {
    lcd.setCursor(0, 0);
    lcd.print(">BuzzWire<       ");
    lcd.setCursor(0, 1);
    lcd.print("                 ");
  }</p><p>  currentButtonState = digitalRead(buttonGCPin);
  if (currentButtonState == HIGH  && lastButtonState == LOW && sensorValue < 500) {
    lcd.setCursor(0, 0);
    lcd.print("Starting:       ");
    lcd.setCursor(0, 1);
    lcd.print("Simon Says      ");
    delay(2000);
    lcd.clear();
    ChoosenGame = 1;
    gameChooser = 0;
  } else if (currentButtonState == HIGH && lastButtonState == LOW && sensorValue > 500) {
    lcd.setCursor(0, 0);
    lcd.print("Starting:       ");
    lcd.setCursor(0, 1);
    lcd.print("BuzzWire        ");
    delay(2000);
    lcd.clear();
    ChoosenGame = 2;
    gameChooser = 0;
  } 
  lastButtonState = currentButtonState;
}</p><p>void victorysound() {
  for (int thisNote = 0; thisNote < 6; thisNote ++) {
    // play the next note:
    speakerpin.play(note[thisNote]);
    // hold the note:
    delay(duration[thisNote]);
    // stop for the next note:
    speakerpin.stop();
    delay(25);
  }
}</p><p>void failsound() {
  for (int y = 0; y <= 2; y++) {
    speakerpin.play(NOTE_G3, 300);
    delay(200);
    speakerpin.play(NOTE_C3, 300);
    delay(200);
  }
}</p><p>////////////////////////////////////////////////////////////////////////
//                                                                    //
//Simon Says Functions                                                //
//                                                                    //
////////////////////////////////////////////////////////////////////////</p><p>void SimonSays() {
  //  for (int y = 0; y <= 99; y++)
  //  {</p><p>  //function for generating the array to be matched by the player
  digitalWrite(ledpin[0], HIGH);
  digitalWrite(ledpin[1], HIGH);
  digitalWrite(ledpin[2], HIGH);
  digitalWrite(ledpin[3], HIGH);</p><p>  for (int thisNote = 0; thisNote < 6; thisNote ++) {
    // play the next note:
    speakerpin.play(note[thisNote]);
    // hold the note:
    delay(duration[thisNote]);
    // stop for the next note:
    speakerpin.stop();
    delay(25);
  }</p><p>  digitalWrite(ledpin[0], LOW);
  digitalWrite(ledpin[1], LOW);
  digitalWrite(ledpin[2], LOW);
  digitalWrite(ledpin[3], LOW);
  delay(1000);</p><p>  for (int y = turnss; y <= turnss; y++)
  { //Limited by the turnss variable
    Serial.println(""); //Some serial output to follow along
    Serial.print("Turn: ");
    Serial.print(y);
    Serial.println("");
    randomArray[y] = random(1, 5); //Assigning a random number (1-4) to the randomArray[y], y being the turnss count
    for (int i = 0; i <= turnss; i++)
    {
      Serial.print(randomArray[i]);</p><p>      for (int y = 0; y < 4; y++)
      {</p><p>        if (randomArray[i] == 1 && ledpin[y] == 22)
        { //if statements to display the stored values in the array
          digitalWrite(ledpin[y], HIGH);
          speakerpin.play(NOTE_G3, 100);
          delay(400);
          digitalWrite(ledpin[y], LOW);
          delay(100);
        }</p><p>        if (randomArray[i] == 2 && ledpin[y] == 23)
        {
          digitalWrite(ledpin[y], HIGH);
          speakerpin.play(NOTE_A3, 100);
          delay(400);
          digitalWrite(ledpin[y], LOW);
          delay(100);
        }</p><p>        if (randomArray[i] == 3 && ledpin[y] == 24)
        {
          digitalWrite(ledpin[y], HIGH);
          speakerpin.play(NOTE_B3, 100);
          delay(400);
          digitalWrite(ledpin[y], LOW);
          delay(100);
        }</p><p>        if (randomArray[i] == 4 && ledpin[y] == 25)
        {
          digitalWrite(ledpin[y], HIGH);
          speakerpin.play(NOTE_C4, 100);
          delay(400);
          digitalWrite(ledpin[y], LOW);
          delay(100);
        }
      }
    }
  }0
  input();</p><p>  //  }</p><p>}</p><p>void input() {</p><p>  for (int i = 0; i <= turnss;)
  {
    for (int y = 0; y < 4; y++)
    {</p><p>      buttonstate = digitalRead(button[y]);</p><p>      if (buttonstate == LOW && button[y] == 26)
      { //Checking for button push
        digitalWrite(ledpin[0], HIGH);
        speakerpin.play(NOTE_G3, 100);
        delay(200);
        digitalWrite(ledpin[0], LOW);
        inputArray[i] = 1;
        delay(250);
        Serial.print(" ");
        Serial.print(1);
        if (inputArray[i] != randomArray[i]) {
          fail();
        }
        i++;
      }
      if (buttonstate == LOW && button[y] == 27)
      {
        digitalWrite(ledpin[1], HIGH);
        speakerpin.play(NOTE_A3, 100);
        delay(200);
        digitalWrite(ledpin[1], LOW);
        inputArray[i] = 2;
        delay(250);
        Serial.print(" ");
        Serial.print(2);
        if (inputArray[i] != randomArray[i]) {
          fail();
        }
        i++;
      }</p><p>      if (buttonstate == LOW && button[y] == 28)
      {
        digitalWrite(ledpin[2], HIGH);
        speakerpin.play(NOTE_B3, 100);
        delay(200);
        digitalWrite(ledpin[2], LOW);
        inputArray[i] = 3;
        delay(250);
        Serial.print(" ");
        Serial.print(3);
        if (inputArray[i] != randomArray[i]) {
          fail();
        }
        i++;
      }</p><p>      if (buttonstate == LOW && button[y] == 29)
      {
        digitalWrite(ledpin[3], HIGH);
        speakerpin.play(NOTE_C4, 100);
        delay(200);
        digitalWrite(ledpin[3], LOW);
        inputArray[i] = 4;
        delay(250);
        Serial.print(" ");
        Serial.print(4);
        if (inputArray[i] != randomArray[i])
        {
          fail();
        }
        i++;
      }
    }
  }
  delay(500);
  turnss++;
  if (turnss == 4) {
    lives = 5;
  }
}</p><p>void fail() {</p><p>  for (int y = 0; y <= 2; y++)
  { //Flashes lights for failure</p><p>    digitalWrite(ledpin[0], HIGH);
    digitalWrite(ledpin[1], HIGH);
    digitalWrite(ledpin[2], HIGH);
    digitalWrite(ledpin[3], HIGH);
    speakerpin.play(NOTE_G3, 300);
    delay(200);
    digitalWrite(ledpin[0], LOW);
    digitalWrite(ledpin[1], LOW);
    digitalWrite(ledpin[2], LOW);
    digitalWrite(ledpin[3], LOW);
    speakerpin.play(NOTE_C3, 300);
    delay(200);
  }
  delay(500);
  turnss--;
  lives--;
  Serial.println("Lives: " + String(lives));
}</p><p>////////////////////////////////////////////////////////////////////////
//                                                                    //
//BuzzWire Functions                                                  //
//                                                                    //
////////////////////////////////////////////////////////////////////////</p><p>void buzzwire() {
  BuzzHit = analogRead(wireRodPin);</p><p>  if (BuzzHit > 1000) {
    Serial.println("lose hit");
    digitalWrite(wireFeedbackPin, HIGH);
    delay(1500);
    digitalWrite(wireFeedbackPin, LOW);
    lives--;
  } else {
    digitalWrite(wireFeedbackPin, LOW);
  }
  currentButtonState = digitalRead(buttonGCPin);
  if (currentButtonState == HIGH  && lastButtonState == LOW) {
    Serial.println("win hit");
    lives = 5;
  }
  lastButtonState = currentButtonState;
}</p>

The code with the DLC:

<p>//Vars for Gameloop<br>#include <LiquidCrystal.h>

int gameChooser = 0;
int ChoosenGame = 0;
int Gamewin = 0;
int scoreP1 = 0;
int scoreP2 = 0;
int Turn = 0;
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
int buttonGCPin = 10;
int buttonSelectPin = 11;
int TurnEnable = 1;
boolean currentButtonState = LOW;
boolean lastButtonState = LOW;</p><p>//Vars for buzzwire
int wireRodPin = A3;
int wireFeedbackPin = 53;
int BuzzHit = 0;</p><p>//Vars for wirepuller
int wireOut1 = 31;
int wireIn1 = 32;
int wireOut2 = 33;
int wireIn2 = 34;
int wireOut3 = 35;
int wireIn3 = 36;
boolean current1 = LOW;
boolean current2 = LOW;
boolean current3 = LOW;
boolean previous1 = LOW;
boolean previous2 = LOW;
boolean previous3 = LOW;
int randNumber = 0;</p><p>//Vars for noisedetector
int micPin = A2;
int micValue = 0;
int micCounter = 1;
int micTimer = 0;
int micSeconds = 0;</p><p>//Vars for quiz
LiquidCrystal lcdquiz(44, 45, 46, 47, 48, 49);
int buttonQuizPin = 52;
boolean currentQuizButtonState = LOW;
boolean lastQuizButtonState = LOW;</p><p>//Vars for Simon Says
#include 
Tone speakerpin;</p><p>int starttune[] = {NOTE_C4, NOTE_F4, NOTE_C4, NOTE_F4, NOTE_C4, NOTE_F4, NOTE_C4, NOTE_F4, NOTE_G4, NOTE_F4, NOTE_E4, NOTE_F4, NOTE_G4};
int duration2[] = {100, 200, 100, 200, 100, 400, 100, 100, 100, 100, 200, 100, 500};
int note[] = {NOTE_C4, NOTE_C4, NOTE_G4, NOTE_C5, NOTE_G4, NOTE_C5};
int duration[] = {100, 100, 100, 300, 100, 300};
int button[] = {26, 27, 28, 29}; //Vier knop pins
int ledpin[] = {22, 23, 24, 25};  // LED pins
int turnss = 0;  // turnss counter
int buttonstate = 0;  // button state checker
int randomArray[100]; //Verschillende volgorde
int inputArray[100];</p><p>//Global vars
int lives = 3;</p><p>void setup() {
  Serial.begin(9600);
  lcd.begin(16, 2);</p><p>  //GameLoop setup
  pinMode(buttonGCPin, INPUT);
  pinMode(buttonSelectPin, INPUT);</p><p>  //Buzzwire setup
  pinMode(wireRodPin, INPUT);
  pinMode(wireFeedbackPin, OUTPUT);</p><p>  //WirePuller Setup
  pinMode(wireOut1, OUTPUT);
  pinMode(wireIn1, INPUT);
  pinMode(wireOut2, OUTPUT);
  pinMode(wireIn2, INPUT);
  pinMode(wireOut3, OUTPUT);
  pinMode(wireIn3, INPUT);
  randomSeed(analogRead(A7));
  randNumber = random(3);
  randNumber++;
  Serial.println(randNumber);</p><p>  //Noisedetector setup
  pinMode(micPin, INPUT);</p><p>  //Quiz setup
  lcdquiz.begin(16, 2);
  pinMode(buttonQuizPin, INPUT);</p><p>  // Simon Says Setup
  speakerpin.begin(30); // speaker op pin 10</p><p>  for (int i = 0; i < 4; i++) {
    pinMode(ledpin[i], OUTPUT);
  }</p><p>  for (int i = 0; i < 4; i++) {
    pinMode(button[i], INPUT);
    digitalWrite(button[i], HIGH);
  }</p><p>  randomSeed(analogRead(15)); //Added to generate "more randomness" with the randomArray for the output function
  for (int thisNote = 0; thisNote < 13; thisNote ++) {
    // play the next note:
    speakerpin.play(starttune[thisNote]);
    // hold the note:
    if (thisNote == 0 || thisNote == 2 || thisNote == 4 || thisNote == 6)
    {
      digitalWrite(ledpin[0], HIGH);
    }
    if (thisNote == 1 || thisNote == 3 || thisNote == 5 || thisNote == 7 || thisNote == 9 || thisNote == 11)
    {
      digitalWrite(ledpin[1], HIGH);
    }
    if (thisNote == 8 || thisNote == 12)
    {
      digitalWrite(ledpin[2], HIGH);
    }
    if (thisNote == 10)
    {
      digitalWrite(ledpin[3], HIGH);
    }
    delay(duration2[thisNote]);
    // stop for the next note:
    speakerpin.stop();
    digitalWrite(ledpin[0], LOW);
    digitalWrite(ledpin[1], LOW);
    digitalWrite(ledpin[2], LOW);
    digitalWrite(ledpin[3], LOW);
    delay(25);
  }
  delay(1000);
}</p><p>void loop() {
  if (Turn == 0 && TurnEnable == 1) {
    lcd.setCursor(0, 0);
    lcd.print("Player 1's turn");
    lcd.setCursor(0, 1);
    lcd.print("Waiting for game");
    currentButtonState = digitalRead(buttonSelectPin);
    if (currentButtonState == HIGH && lastButtonState == LOW) {
      gameChooser = 1;
      TurnEnable = 0;
      lcd.clear();
    }
  }
  if (Turn == 1 && TurnEnable == 1) {
    lcd.setCursor(0, 0);
    lcd.print("Player 2's turn");
    lcd.setCursor(0, 1);
    lcd.print("Waiting for game");
    currentButtonState = digitalRead(buttonSelectPin);
    if (currentButtonState == HIGH && lastButtonState == LOW) {
      gameChooser = 1;
      TurnEnable = 0;
      lcd.clear();
    }
  }</p><p>  if (gameChooser == 1) {
    gamePicker();
  }
  lastButtonState = currentButtonState;</p><p>  //Simon Says
  if (ChoosenGame == 1) {
    lcd.setCursor(0, 0);
    lcd.print("Playing:");
    lcd.setCursor(0, 1);
    lcd.print("Simon Says");
    if (lives == 0) {
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("Player " + String(Turn + 1));
      lcd.setCursor(0, 1);
      lcd.print("Is Gameover!");
      failsound();
      delay(2500);
      ChoosenGame = 0;
      turnss = 0;
      TurnSwitch();
    } else if (lives == 5) {
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("Player " + String(Turn + 1));
      lcd.setCursor(0, 1);
      lcd.print("Gained a point!");
      delay(2500);
      victorysound();
      ChoosenGame = 0;
      turnss = 0;
      TurnSwitch();
    } else {
      SimonSays();
    }
  }</p><p>  // WirePuller
  if (ChoosenGame == 2) {
    lcd.setCursor(0, 0);
    lcd.print("Playing:");
    lcd.setCursor(0, 1);
    lcd.print("Wirepuller");
    wirepuller();
    if (lives == 0) {
      lcdquiz.clear();
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("Player " + String(Turn + 1));
      lcd.setCursor(0, 1);
      lcd.print("Is Gameover!");
      failsound();
      delay(2500);
      ChoosenGame = 0;
      TurnSwitch();
    } else if (lives == 5) {
      lcdquiz.clear();
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("Player " + String(Turn + 1));
      lcd.setCursor(0, 1);
      lcd.print("Gained a point!");
      delay(2500);
      victorysound();
      ChoosenGame = 0;
      TurnSwitch();
    }
  }
  //BuzzWire
  if (ChoosenGame == 3) {
    lcd.setCursor(0, 0);
    lcd.print("Playing:");
    lcd.setCursor(0, 1);
    lcd.print("BuzzWire");
    buzzwire();
    if (lives == 0) {
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("Player " + String(Turn + 1));
      lcd.setCursor(0, 1);
      lcd.print("Is Gameover!");
      failsound();
      delay(2500);
      ChoosenGame = 0;
      TurnSwitch();
    } else if (lives == 5) {
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("Player " + String(Turn + 1));
      lcd.setCursor(0, 1);
      lcd.print("Gained a point!");
      delay(2500);
      victorysound();
      ChoosenGame = 0;
      TurnSwitch();
    }
  }
  //NoiseDetector
  if (ChoosenGame == 4) {
    lcd.setCursor(0, 0);
    lcd.print("Playing:");
    lcd.setCursor(0, 1);
    lcd.print("Noisedetector");
    noisedetector();
    if (lives == 0) {
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("Player " + String(Turn + 1));
      lcd.setCursor(0, 1);
      lcd.print("Is Gameover!");
      failsound();
      delay(2500);
      ChoosenGame = 0;
      TurnSwitch();
    } else if (lives == 5) {
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("Player " + String(Turn + 1));
      lcd.setCursor(0, 1);
      lcd.print("Gained a point!");
      delay(2500);
      victorysound();
      ChoosenGame = 0;
      TurnSwitch();
    }
  }
  //Quiz
  if (ChoosenGame == 5) {
    quiz();
    if (lives == 0) {
      lcd.clear();
      lcdquiz.clear();
      lcd.setCursor(0, 0);
      lcd.print("Player " + String(Turn + 1));
      lcd.setCursor(0, 1);
      lcd.print("Is Gameover!");
      failsound();
      delay(2500);
      ChoosenGame = 0;
      TurnSwitch();
    } else if (lives == 5) {
      lcd.clear();
      lcdquiz.clear();
      lcd.setCursor(0, 0);
      lcd.print("Player " + String(Turn + 1));
      lcd.setCursor(0, 1);
      lcd.print("Gained a point!");
      delay(2500);
      victorysound();
      ChoosenGame = 0;
      TurnSwitch();
    }
  }
}</p><p>////////////////////////////////////////////////////////////////////////
//                                                                    //
//Game Functions                                         //
//                                                                    //
////////////////////////////////////////////////////////////////////////</p><p>void TurnSwitch() {
  if (Turn == 0) {
    Turn = 1;
    TurnEnable = 1;
    lives = 3;
  } else if (Turn == 1) {
    Turn = 0;
    TurnEnable = 1;
    lives = 3;
  }
}</p><p>void gamePicker() {
  int sensorValue = analogRead(A0);
  //game kies menu
  if (sensorValue < 200) {
    lcd.setCursor(0, 0);       //
    lcd.print(">Simon Says<     ");
    lcd.setCursor(0, 1);
    lcd.print("WirePuller      ");
  } else if (sensorValue > 200 && sensorValue < 400) {
    lcd.setCursor(0, 0);
    lcd.print(">WirePuller<    ");
    lcd.setCursor(0, 1);
    lcd.print("BuzzWire        ");
  } else if (sensorValue > 400 && sensorValue < 600) {
    lcd.setCursor(0, 0);
    lcd.print(">BuzzWire<       ");
    lcd.setCursor(0, 1);
    lcd.print("NoiseDetector   ");
  } else if (sensorValue > 600 && sensorValue < 800) {
    lcd.setCursor(0, 0);
    lcd.print(">NoiseDetector< ");
    lcd.setCursor(0, 1);
    lcd.print("Quiz             ");
  } else if (sensorValue > 800) {
    lcd.setCursor(0, 0);
    lcd.print(">Quiz<          ");
    lcd.setCursor(0, 1);
    lcd.print("                 ");
  }</p><p>  currentButtonState = digitalRead(buttonGCPin);
  if (currentButtonState == HIGH  && lastButtonState == LOW && sensorValue < 200) {
    lcd.setCursor(0, 0);
    lcd.print("Starting:       ");
    lcd.setCursor(0, 1);
    lcd.print("Simon Says      ");
    delay(2000);
    lcd.clear();
    ChoosenGame = 1;
    gameChooser = 0;
  } else if (currentButtonState == HIGH && lastButtonState == LOW && sensorValue > 200 && sensorValue < 400) {
    lcd.setCursor(0, 0);
    lcd.print("Starting:       ");
    lcd.setCursor(0, 1);
    lcd.print("WirePuller      ");
    delay(2000);
    lcd.clear();
    ChoosenGame = 2;
    gameChooser = 0;
  } else if (currentButtonState == HIGH && lastButtonState == LOW && sensorValue > 400 && sensorValue < 600) {
    lcd.setCursor(0, 0);
    lcd.print("Starting:       ");
    lcd.setCursor(0, 1);
    lcd.print("BuzzWire        ");
    delay(2000);
    lcd.clear();
    ChoosenGame = 3;
    gameChooser = 0;
  } else if (currentButtonState == HIGH && lastButtonState == LOW && sensorValue > 600 && sensorValue < 800) {
    lcd.setCursor(0, 0);
    lcd.print("Starting:       ");
    lcd.setCursor(0, 1);
    lcd.print("NoiseDetector   ");
    delay(2000);
    lcd.clear();
    ChoosenGame = 4;
    gameChooser = 0;
  } else if (currentButtonState == HIGH && lastButtonState == LOW && sensorValue > 800) {
    lcd.setCursor(0, 0);
    lcd.print("Starting:       ");
    lcd.setCursor(0, 1);
    lcd.print("Quiz            ");
    delay(2000);
    lcd.clear();
    ChoosenGame = 5;
    gameChooser = 0;
  }
  lastButtonState = currentButtonState;
}</p><p>void victorysound() {
  for (int thisNote = 0; thisNote < 6; thisNote ++) {
    // play the next note:
    speakerpin.play(note[thisNote]);
    // hold the note:
    delay(duration[thisNote]);
    // stop for the next note:
    speakerpin.stop();
    delay(25);
  }
}</p><p>void failsound() {
  for (int y = 0; y <= 2; y++) {
    speakerpin.play(NOTE_G3, 300);
    delay(200);
    speakerpin.play(NOTE_C3, 300);
    delay(200);
  }
}</p><p>////////////////////////////////////////////////////////////////////////
//                                                                    //
//Simon Says Functions                                                //
//                                                                    //
////////////////////////////////////////////////////////////////////////</p><p>void SimonSays() {
  //  for (int y = 0; y <= 99; y++)
  //  {</p><p>  //function for generating the array to be matched by the player
  digitalWrite(ledpin[0], HIGH);
  digitalWrite(ledpin[1], HIGH);
  digitalWrite(ledpin[2], HIGH);
  digitalWrite(ledpin[3], HIGH);</p><p>  for (int thisNote = 0; thisNote < 6; thisNote ++) {
    // play the next note:
    speakerpin.play(note[thisNote]);
    // hold the note:
    delay(duration[thisNote]);
    // stop for the next note:
    speakerpin.stop();
    delay(25);
  }</p><p>  digitalWrite(ledpin[0], LOW);
  digitalWrite(ledpin[1], LOW);
  digitalWrite(ledpin[2], LOW);
  digitalWrite(ledpin[3], LOW);
  delay(1000);</p><p>  for (int y = turnss; y <= turnss; y++)
  { //Limited by the turnss variable
    Serial.println(""); //Some serial output to follow along
    Serial.print("Turn: ");
    Serial.print(y);
    Serial.println("");
    randomArray[y] = random(1, 5); //Assigning a random number (1-4) to the randomArray[y], y being the turnss count
    for (int i = 0; i <= turnss; i++)
    {
      Serial.print(randomArray[i]);</p><p>      for (int y = 0; y < 4; y++)
      {</p><p>        if (randomArray[i] == 1 && ledpin[y] == 22)
        { //if statements to display the stored values in the array
          digitalWrite(ledpin[y], HIGH);
          speakerpin.play(NOTE_G3, 100);
          delay(400);
          digitalWrite(ledpin[y], LOW);
          delay(100);
        }</p><p>        if (randomArray[i] == 2 && ledpin[y] == 23)
        {
          digitalWrite(ledpin[y], HIGH);
          speakerpin.play(NOTE_A3, 100);
          delay(400);
          digitalWrite(ledpin[y], LOW);
          delay(100);
        }</p><p>        if (randomArray[i] == 3 && ledpin[y] == 24)
        {
          digitalWrite(ledpin[y], HIGH);
          speakerpin.play(NOTE_B3, 100);
          delay(400);
          digitalWrite(ledpin[y], LOW);
          delay(100);
        }</p><p>        if (randomArray[i] == 4 && ledpin[y] == 25)
        {
          digitalWrite(ledpin[y], HIGH);
          speakerpin.play(NOTE_C4, 100);
          delay(400);
          digitalWrite(ledpin[y], LOW);
          delay(100);
        }
      }
    }
  }0
  input();</p><p>  //  }</p><p>}</p><p>void input() {</p><p>  for (int i = 0; i <= turnss;)
  {
    for (int y = 0; y < 4; y++)
    {</p><p>      buttonstate = digitalRead(button[y]);</p><p>      if (buttonstate == LOW && button[y] == 26)
      { //Checking for button push
        digitalWrite(ledpin[0], HIGH);
        speakerpin.play(NOTE_G3, 100);
        delay(200);
        digitalWrite(ledpin[0], LOW);
        inputArray[i] = 1;
        delay(250);
        Serial.print(" ");
        Serial.print(1);
        if (inputArray[i] != randomArray[i]) {
          fail();
        }
        i++;
      }
      if (buttonstate == LOW && button[y] == 27)
      {
        digitalWrite(ledpin[1], HIGH);
        speakerpin.play(NOTE_A3, 100);
        delay(200);
        digitalWrite(ledpin[1], LOW);
        inputArray[i] = 2;
        delay(250);
        Serial.print(" ");
        Serial.print(2);
        if (inputArray[i] != randomArray[i]) {
          fail();
        }
        i++;
      }</p><p>      if (buttonstate == LOW && button[y] == 28)
      {
        digitalWrite(ledpin[2], HIGH);
        speakerpin.play(NOTE_B3, 100);
        delay(200);
        digitalWrite(ledpin[2], LOW);
        inputArray[i] = 3;
        delay(250);
        Serial.print(" ");
        Serial.print(3);
        if (inputArray[i] != randomArray[i]) {
          fail();
        }
        i++;
      }</p><p>      if (buttonstate == LOW && button[y] == 29)
      {
        digitalWrite(ledpin[3], HIGH);
        speakerpin.play(NOTE_C4, 100);
        delay(200);
        digitalWrite(ledpin[3], LOW);
        inputArray[i] = 4;
        delay(250);
        Serial.print(" ");
        Serial.print(4);
        if (inputArray[i] != randomArray[i])
        {
          fail();
        }
        i++;
      }
    }
  }
  delay(500);
  turnss++;
  if (turnss == 4) {
    lives = 5;
  }
}</p><p>void fail() {</p><p>  for (int y = 0; y <= 2; y++)
  { //Flashes lights for failure</p><p>    digitalWrite(ledpin[0], HIGH);
    digitalWrite(ledpin[1], HIGH);
    digitalWrite(ledpin[2], HIGH);
    digitalWrite(ledpin[3], HIGH);
    speakerpin.play(NOTE_G3, 300);
    delay(200);
    digitalWrite(ledpin[0], LOW);
    digitalWrite(ledpin[1], LOW);
    digitalWrite(ledpin[2], LOW);
    digitalWrite(ledpin[3], LOW);
    speakerpin.play(NOTE_C3, 300);
    delay(200);
  }
  delay(500);
  turnss--;
  lives--;
  Serial.println("Lives: " + String(lives));
}</p><p>////////////////////////////////////////////////////////////////////////
//                                                                    //
//WirePuller Functions                                                //
//                                                                    //
////////////////////////////////////////////////////////////////////////</p><p>void wirepuller() {
  digitalWrite(wireOut1, HIGH);
  digitalWrite(wireOut2, HIGH);
  digitalWrite(wireOut3, HIGH);
  current1 = digitalRead(wireIn1);
  current2 = digitalRead(wireIn2);
  current3 = digitalRead(wireIn3);
  Serial.println(String(current1) + " " + String(previous1));
  Serial.println(String(current2) + " " + String(previous2));
  Serial.println(String(current3) + " " + String(previous3));
  Serial.println(randNumber);
  if (current1 == previous1 && randNumber == 1) {
    
  Serial.println("le eerste win");
    lcdquiz.clear();
    lcdquiz.setCursor(0, 0);
    lcdquiz.print("You pulled");
    lcdquiz.setCursor(0, 1);
    lcdquiz.print("the right wire");
    delay(2500);
    lcdquiz.clear();
    lives = 5;
  } else if (current1 == previous1) {
  Serial.println("le eerste");
    lcdquiz.clear();
    lcdquiz.setCursor(0, 0);
    lcdquiz.print("You pulled");
    lcdquiz.setCursor(0, 1);
    lcdquiz.print("the wrong wire");
    delay(2500);
    lcdquiz.clear();
    lives = 0;
  }
  if (current2 == previous2 && randNumber == 2) {
    
  Serial.println("le tweetste win");
    lcdquiz.clear();
    lcdquiz.setCursor(0, 0);
    lcdquiz.print("You pulled");
    lcdquiz.setCursor(0, 1);
    lcdquiz.print("the right wire");
    delay(2500);
    lcdquiz.clear();
    lives = 5;
  } else if (current2 == previous2) {
    
  Serial.println("le tweeste");
    lcdquiz.clear();
    lcdquiz.setCursor(0, 0);
    lcdquiz.print("You pulled");
    lcdquiz.setCursor(0, 1);
    lcdquiz.print("the wrong wire");
    delay(2500);
    lcdquiz.clear();
    lives = 0;
  }
  if (current3 == previous3 && randNumber == 3) {</p><p>  Serial.println("le drieste win");
    lcdquiz.clear();
    lcdquiz.setCursor(0, 0);
    lcdquiz.print("You pulled");
    lcdquiz.setCursor(0, 1);
    lcdquiz.print("the right wire");
    delay(2500);
    lcdquiz.clear();
    lives = 5;
  } else if (current3 == previous3) {
    
  Serial.println("le drieste");
    lcdquiz.clear();
    lcdquiz.setCursor(0, 0);
    lcdquiz.print("You pulled");
    lcdquiz.setCursor(0, 1);
    lcdquiz.print("the wrong wire");
    delay(2500);
    lcdquiz.clear();
    lives = 0;
  }
  previous1 = current1;
  previous2 = current2;
  previous3 = current3;
  
  digitalWrite(wireOut1, LOW);
  digitalWrite(wireOut2, LOW);
  digitalWrite(wireOut3, LOW);
   current1 = digitalRead(wireIn1);
  current2 = digitalRead(wireIn2);
  current3 = digitalRead(wireIn3);
  if (current1 == previous1 && randNumber == 1) {
    
  Serial.println("le eerste win check 2");
    lcdquiz.clear();
    lcdquiz.setCursor(0, 0);
    lcdquiz.print("You pulled");
    lcdquiz.setCursor(0, 1);
    lcdquiz.print("the right wire");
    delay(2500);
    lcdquiz.clear();
    lives = 5;
  } else if (current1 == previous1) {
    
  Serial.println("le eerste check 2");
    lcdquiz.clear();
    lcdquiz.setCursor(0, 0);
    lcdquiz.print("You pulled");
    lcdquiz.setCursor(0, 1);
    lcdquiz.print("the wrong wire");
    delay(2500);
    lcdquiz.clear();
    lives = 0;
  }
  if (current2 == previous2 && randNumber == 2) {
    
  Serial.println("le tweerste win check 2");
    lcdquiz.clear();
    lcdquiz.setCursor(0, 0);
    lcdquiz.print("You pulled");
    lcdquiz.setCursor(0, 1);
    lcdquiz.print("the right wire");
    delay(2500);
    lcdquiz.clear();
    lives = 5;
  } else if (current2 == previous2) {
    
  Serial.println("le tweerste check 2");
    lcdquiz.clear();
    lcdquiz.setCursor(0, 0);
    lcdquiz.print("You pulled");
    lcdquiz.setCursor(0, 1);
    lcdquiz.print("the wrong wire");
    delay(2500);
    lcdquiz.clear();
    lives = 0;
  }
  if (current3 == previous3 && randNumber == 3) {</p><p>  Serial.println("le driederste win check 2");
    lcdquiz.clear();
    lcdquiz.setCursor(0, 0);
    lcdquiz.print("You pulled");
    lcdquiz.setCursor(0, 1);
    lcdquiz.print("the right wire");
    delay(2500);
    lcdquiz.clear();
    lives = 5;
  } else if (current3 == previous3){
    
  Serial.println("le driederste check 2");
    lcdquiz.clear();
    lcdquiz.setCursor(0, 0);
    lcdquiz.print("You pulled");
    lcdquiz.setCursor(0, 1);
    lcdquiz.print("the wrong wire");
    delay(2500);
    lcdquiz.clear();
    lives = 0;
  }
  previous1 = current1;
  previous2 = current2;
  previous3 = current3;
}</p><p>////////////////////////////////////////////////////////////////////////
//                                                                    //
//BuzzWire Functions                                                  //
//                                                                    //
////////////////////////////////////////////////////////////////////////</p><p>void buzzwire() {
  BuzzHit = analogRead(wireRodPin);</p><p>  if (BuzzHit > 1000) {
    Serial.println("lose hit");
    digitalWrite(wireFeedbackPin, HIGH);
    delay(1500);
    digitalWrite(wireFeedbackPin, LOW);
    lives--;
  } else {
    digitalWrite(wireFeedbackPin, LOW);
  }
  currentButtonState = digitalRead(buttonGCPin);
  if (currentButtonState == HIGH  && lastButtonState == LOW) {
    Serial.println("win hit");
    lives = 5;
  }
  lastButtonState = currentButtonState;
}</p><p>

////////////////////////////////////////////////////////////////////////
// // //NoiseDetector Functions // // // ////////////////////////////////////////////////////////////////////////

void noisedetector() { lcdquiz.setCursor(0, 0); lcdquiz.print("GO GO GO!"); if (micSeconds > 10) { lcdquiz.setCursor(0, 0); lcdquiz.print("You lose!"); micTimer = 0; micCounter = 0; micSeconds = 0; delay(1000); lives = 0; lcdquiz.clear(); } else { if (micCounter > 500) { micCounter = 0; micTimer = 0; micSeconds = 0; lcdquiz.setCursor(0, 0); lcdquiz.print("You win!"); delay(1000); lives = 5; lcdquiz.clear(); } micValue = analogRead(micPin); Serial.println(micValue); if (micValue > 95) { micCounter++; lcdquiz.setCursor(0, 1); lcdquiz.print(micCounter); } micTimer++; if (micTimer == 150) { micSeconds++ ; micTimer = 0; } } }

//////////////////////////////////////////////////////////////////////// // // //Quiz Functions // // // //////////////////////////////////////////////////////////////////////// </p><p>void quiz() { int sensorValue = analogRead(A1); lcd.setCursor(0, 0); lcd.print("How old is"); lcd.setCursor(0, 1); lcd.print("Floris?"); if (sensorValue < 250) { lcdquiz.setCursor(0, 0); // lcdquiz.print(">20< 21 "); lcdquiz.setCursor(0, 1); lcdquiz.print(" 22 23 "); } else if (sensorValue > 250 && sensorValue < 500) { lcdquiz.setCursor(0, 0); lcdquiz.print(" 20 >21< "); lcdquiz.setCursor(0, 1); lcdquiz.print(" 22 23 "); } else if (sensorValue > 500 && sensorValue < 750) { lcdquiz.setCursor(0, 0); lcdquiz.print(" 20 21 "); lcdquiz.setCursor(0, 1); lcdquiz.print(">22< 23 "); } else if (sensorValue > 750) { lcdquiz.setCursor(0, 0); lcdquiz.print(" 20 21 "); lcdquiz.setCursor(0, 1); lcdquiz.print(" 22 >23< "); }</p><p> currentQuizButtonState = digitalRead(buttonQuizPin); if (currentQuizButtonState == HIGH && lastQuizButtonState == LOW && sensorValue > 750) { lcd.clear(); lcd.setCursor(0, 0); lcd.print("Correct!"); delay(2500); lives = 5; } else if (currentQuizButtonState == HIGH && lastQuizButtonState == LOW && sensorValue < 750) { lcd.clear(); lcd.setCursor(0, 0); lcd.print("Wrong!"); lcd.setCursor(0, 1); lcd.print("Try again!"); delay(2500); lcd.clear(); lives--; } lastQuizButtonState = currentQuizButtonState; </p>

Step 17: Making the Case

Now it is time for a case to put all of the parts in. I made a case with www.makercase.com and adapted the top to fit all of our games. First we created a sketch of the playing field. This is the picture above. Then i started to make the laserprinting planns. The entire case is 400x300x100 that is the size for the entire module.

Step 18: Making the Case - Cutting the Case

Here are the laser cutting plans for the case. These plans are made for 3MM triplex wood. The minimal size for the plate of wood is 400x700 if you're using a smaller piece of wood you will have to move some stuff around.

Note: its important to remove the bottom hole if you are making the no dlc version in the .ai file before you lasercut the case. Otherwise you will have a hole that serves no purpose.

Step 19: Marking the Board.

When you are done with lasercutting the case and you have put it together you can make the playing field. We chose a figure 8 playing field but the choise is yours. The rest of the led and games must be assigned asswell. you can choose your own place for these modules. we chose to put them in the corners. For the led is a 5mm drill bit fine. the led's will go in fine with a little pressure.

Step 20: Putting It All Together

when you are done with creating the case and the board. you are ready to put it all together. start by putting in the screen and the other parts that need to be screwed down. when you have all of those parts fitted into the cover start putting your arduino inside. You need to see what setup of arduino works best for you. The picture above is how my gamecase looks from the inside and its a mess. i suggest sorting the wire's and wrapping the wires together if possible it saves you a lot of irritation.

Step 21: The Finished Product

When it its finished the game should look something like this. If you have any questions regarding the game feel free to ask them in the comments.