loading

Conceptidea

The idea is to make a SMART Boardgame, controlled and operated by (possibly) multiple Arduino's. There are multiple modules attached to the boardgame that determine the flow of the game and players have to complete these modules rean points to advance through the game.

In this instructable, I will focus on my modules, which are an extention to the total board game I have developed with a friend (that instructable can be found over here). He will do his own modules on his own and our projects combined together we will create one big game with lots of variety between the different modules to create an intresting and exciting experience.

Step 1: Concept Analysis

MoSCoW Analysis

Must have: Digital dice module

Should have: Quiz module, Wire puller module, Noise detector module

Could have: Color finder module, Smart dice module

Won’t have:

Quick overview of IO Components

Digital dice: LEDs, Button (Or alternatively order something like this: http://goo.gl/B9Fn0d)

Quiz: LCD, Potentiometer, Button

Wire puller: LCD, Wires as input

Noise detector: LCD, Sound sensor (Order a small soundboard similar to: http://goo.gl/ajuX8R)

Color finder: LCD, Color sensor (Did not construct in the end)

Smart dice: Gyroscope, Speaker (Did not construct in the end)

Step 2: Construction

Since this is an extention to the SMART Boardgame's Gamecontroller, this project is not meant to be run on its own. But for the sake of demonstration, all of these modules could be run on a single, separate arduino, as seen in the Fritzing schematic above and the snippets of code provided in the next steps. I have color coded each separate module for easy overview:

  • The Dice Module is running using the green colored wires, the 7 LEDs and the button.
  • The Wire Module is running using the blue colored wires which are connected immediately to other ports.
  • The Quiz Module is running using the yellow colored wires, 2 potentiometers (contrast and input) and the button.
  • The Noise Module is running using the orange colored wires connected to the sound sensor.

All of this is contained in a wooden box which is designed using MakerCase which we cut out using a laser cutter in our local FabLab, the plans can be found here. We made space on top for the various game modules to fit through, so the players can play the games without opening the box.

Step 3: Dice

Originally I wanted to order a finished dice module (http://goo.gl/15SdVS) so I had time to create other modules, but the product was not present in the warehouse so I decided to create my own dice module.

In order to save I/O ports on my Arduino, I grouped the LEDs into 4 groups. The 4 groups are:

  • Top right and bottom left
  • Top left and bottom right
  • Middle left and middle right
  • The last one in the middle

These 4 groups should cover every shape that the die rolls from 1 to 6 form. When a button is pressed, a random number is generated and the LEDs in the according groups are lit.

int group1 = A0;<br>int group2 = A1;
int group3 = A2;
int group4 = A3;
int buttonPin = 0;
boolean currentButtonState = LOW;
boolean previousButtonState = LOW;
int ran = 0;
int time = 2500;<br><br>void setup () {
  Serial.begin(9600);
  pinMode (group1, OUTPUT);
  pinMode (group2, OUTPUT);
  pinMode (group3, OUTPUT);
  pinMode (group4, OUTPUT);
  pinMode (buttonPin, INPUT);
  randomSeed(analogRead(0));
}<br><br>void loop() {
  currentButtonState = digitalRead(buttonPin);
  if (currentButtonState == HIGH && previousButtonState == LOW) {
    ran = random(1, 7);
    Serial.println(ran);
    if (ran == 1) {
      digitalWrite (group1, HIGH);
      delay (time);
    }
    if (ran == 2) {
      digitalWrite (group2, HIGH);
      delay (time);
    }
    if (ran == 3) {
      digitalWrite (group1, HIGH);
      digitalWrite (group2, HIGH);
      delay (time);
    }
    if (ran == 4) {
      digitalWrite (group2, HIGH);
      digitalWrite (group3, HIGH);
      delay (time);
    }
    if (ran == 5) {
      digitalWrite (group1, HIGH);
      digitalWrite (group2, HIGH);
      digitalWrite (group3, HIGH);
      delay (time);
    }
    if (ran == 6) {
      digitalWrite (group2, HIGH);
      digitalWrite (group3, HIGH);
      digitalWrite (group4, HIGH);
      delay (time);
    }
  }
  previousButtonState = currentButtonState;
  digitalWrite (group1, LOW);
  digitalWrite (group2, LOW);
  digitalWrite (group3, LOW);
  digitalWrite (group4, LOW);
}

Step 4: Wire Puller Module

I wanted to make a bomb-style wire cutter game, but that would require replaceable parts. I remebered I had female headers on some wires, which allow us to leave the connection of 2 wires visible to be pulled apart.

It uses a random wire as the correct target and it constantly checks whether the wrong input is measured that is not sent through that wire.

int wireOut1 = 6;<br>int wireIn1 = 7;
int wireOut2 = 8;
int wireIn2 = 9;
int wireOut3 = 10;
int wireIn3 = 13;
boolean current1 = LOW;
boolean current2 = LOW;
boolean current3 = LOW;
boolean previous1 = LOW;
boolean previous2 = LOW;
boolean previous3 = LOW;
int randNumber = 0;<br><br>void setup() {
  Serial.begin(9600);
  pinMode(wireOut1, OUTPUT);
  pinMode(wireIn1, INPUT);
  pinMode(wireOut2, OUTPUT);
  pinMode(wireIn2, INPUT);
  pinMode(wireOut3, OUTPUT);
  pinMode(wireIn3, INPUT);
  Serial.println("Program begun");
  randomSeed(analogRead(A1));
  randNumber = random(3);
  randNumber++;
  Serial.println(randNumber);
}<br><br>void loop() {
  digitalWrite(wireOut1, HIGH);
  digitalWrite(wireOut2, HIGH);
  digitalWrite(wireOut3, HIGH);
  current1 = digitalRead(wireIn1);
  current2 = digitalRead(wireIn2);
  current3 = digitalRead(wireIn3);
  if (current1 == previous1 && randNumber == 1) {
    Serial.println("Win");
  } else if (current1 == previous1) {
    Serial.println("Lose");
  }
  if (current2 == previous2 && randNumber == 2) {
    Serial.println("Win");
  } else if (current2 == previous2) {
    Serial.println("Lose");
  }
  if (current3 == previous3 && randNumber == 3) {
    Serial.println("Win");
  } else if (current3 == previous3) {
    Serial.println("Lose");
  }
  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("Win");
  } else if (current1 == previous1) {
    Serial.println("Lose");
  }
  if (current2 == previous2 && randNumber == 2) {
    Serial.println("Win");
  } else if (current2 == previous2) {
    Serial.println("Lose");
  }
  if (current3 == previous3 && randNumber == 3) {
    Serial.println("Win");
  } else if (current3 == previous3) {
    Serial.println("Lose");
  }
  previous1 = current1;
  previous2 = current2;
  previous3 = current2;
}

Step 5: Quiz Module

I wanted to make simple quiz module that uses an intresting controlling mechanism. The potentiometer controls a cursor that 'selects' an answer on the LCD. When the button is pressed, that answer is chosen and determines whether the players answered correctly or not.

<p>#include LiquidCrystal lcd(12, 11, 5, 4, 3, 2);<br>int buttonPin = 1;
int potMeterPin = A5;
boolean currentButtonState = LOW;
boolean lastButtonState = LOW;</p><p>void setup() {
  Serial.begin(9600);
  lcd.begin(16, 2);
  pinMode(buttonPin, INPUT);
  pinMode(potmeterPin, INPUT);
  Serial.println("Your question here?");
}</p><p>void loop() {
  int sensorValue = analogRead(potMeterPin);
  if (sensorValue < 250) {
    lcd.setCursor(0, 0);       //
    lcd.print(">A1<     A2     ");
    lcd.setCursor(0, 1);
    lcd.print(" A3      A4     ");
  } else if (sensorValue > 250 && sensorValue < 500) {
    lcd.setCursor(0, 0);
    lcd.print(" A1     >A2<    ");</p><p>    lcd.setCursor(0, 1);
    lcd.print(" A3      A4     ");</p><p>  } else if (sensorValue > 500 && sensorValue < 750) {
    lcd.setCursor(0, 0);
    lcd.print(" A1      A2     ");</p><p>    lcd.setCursor(0, 1);
    lcd.print(">A3<     A4     ");</p><p>  } else if (sensorValue > 750) {
    lcd.setCursor(0, 0);
    lcd.print(" A1      A2     ");</p><p>    lcd.setCursor(0, 1);
    lcd.print(" A3     >A4<    ");
  }
  currentButtonState = digitalRead(buttonPin);
  if (currentButtonState == HIGH  && lastButtonState == LOW && sensorValue > 750) {
    Serial.println("True!");
  } else if (currentButtonState == HIGH && lastButtonState == LOW && sensorValue < 750) {
    Serial.println("False!");
  }
  lastButtonState = currentButtonState;
}</p>

Step 6: Noise Detector Module

The noise detector module turned out to be a big more annoying to construct than others. I purchased a sound sensor that always gave the maximum output, no matter how much I turned that pot-meter that was fixed on the board. I purchased a new one and set it up correctly such that it only outputs a high signal if it measures sound.

The sound is measured for how long you keep making noise. The player needs to make noise for a certain amount of time before the program times out and the player loses. If the player makes enough noise before the program expires, the player wins.

<p>int micPin = A4;
int micValue = 0;
int micCounter = 1;
int micTimer = 0;
int micSeconds = 0;</p><p>void setup() {
  Serial.begin(9600);
  pinMode(micPin, INPUT);
  Serial.println("Start!");
}</p><p>void loop() {
  if (micSeconds > 10) {
    Serial.println("You lose!");
    micTimer = 0;
    micSeconds = 0;
    delay(1000);
  } else {
    if (micCounter > 1000) {
      Serial.println("You win!");
      micCounter = 0;
      micTimer = 0;
      micSeconds = 0;
    }
    micValue = analogRead(micPin);
    if (micValue > 100) {
      micCounter++;
      Serial.println(micCounter);
    }
    micTimer++;
    if (micTimer == 10000) {
      micSeconds++ ;
      micTimer = 0;
    }
  }
}</p>

Step 7: The Finished Product

This is the combined code file using the GameController from the main game of this instrucable that this instructable is an extention of. If this part of the game is to be run alone, the code below must be stripped of the games that are not included.

//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;</liquidcrystal.h></p><p>//Global vars int lives = 3; int TurnEnable = 1; int Turn = 0; 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.h> Tone speakerpin;</tone.h></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>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!"); victorysound(); delay(2500); 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!"); victorysound(); delay(2500); 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!"); victorysound(); delay(2500); 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!"); victorysound(); delay(2500); 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!"); victorysound(); delay(2500);; ChoosenGame = 0; TurnSwitch(); } } }</p><p>//////////////////////////////////////////////////////////////////////// // // //Game Picker 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() { //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); } } } } input();</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) {</p><p> 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) {</p><p> 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) {</p><p> 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) {</p><p> 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;</p><p> digitalWrite(wireOut1, LOW); digitalWrite(wireOut2, LOW); digitalWrite(wireOut3, LOW); current1 = digitalRead(wireIn1); current2 = digitalRead(wireIn2); current3 = digitalRead(wireIn3); if (current1 == previous1 && randNumber == 1) {</p><p> 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) {</p><p> 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) {</p><p> 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) {</p><p> 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) {</p><p> 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); if (BuzzHit == 1023) { 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 // // // ////////////////////////////////////////////////////////////////////////</p><p>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; } } }</p><p>//////////////////////////////////////////////////////////////////////// // // //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>
<p>Hi, firstly, this project is really cool, so well done to you and your friend! </p><p>I have seen both instructables, and I wanted to ask if i were to follow these instructions exactly, how would I combine the two into one board game?</p>
<p>cool</p>
<p>Cool board game</p>

About This Instructable

1,873views

24favorites

License:

More by Florisch:SMART Boardgame 
Add instructable to: