2023 Group 1 – Trifecta

PROJECT BRIEF

Escape rooms require you to solve a series of puzzles within a time limit to escape. Create a puzzle for participants to solve using the skills you’ve learnt. Your puzzle might include a sequence of things to solve, should offer some help if participants get stuck, whilst also rewarding them on its completion. You are asked to design an Arduino based circuit that could be used as part of an escape room

Purpose

To entertain children with a fun interactive puzzle which keeps them engrossed. Various components like potentiometer, buttons and keypad will be used as a source of input from the user and a visual or auditory would be provided as an output.

Target Audience

The targeted demographic is older children between the age of 8-13 which are looking for an interesting puzzle/ game. Puzzles like these could be really fun for them and can help improve short term memory, fine motor skills and mental speed.

Market Research

1. Talking Tables Escape Room Kyoto Edition

With a playtime of 60 minutes, it’s a fun-filled quick game for an evening with friends. So hosts and players can gather their teams, sharpen their minds, and get ready to embark on an unforgettable adventure through the streets of Kyoto. Will you be able to solve the puzzles and escape before time runs out?

2. Cluebox “The Trial of Camelot”

This is a portable Escape Room game which has a playtime of 60 – 90 minutes. This involves various engaging puzzles you need to do to complete the game.

3. Professor Puzzle Escape Room Game

In this game you’ll move through the hotel solving the series of interactive puzzles to release you from each room. The ultimate quest being to uncover the dark, hidden secret of The Grand Hotel.

Conclusion

All these above games are really interesting and look really fun to play, but these games take really long to finish and only consist of visual cues. The targeted audience has a really short attention span so we can’t expect them to sit still and complete an hour long game. So our game would be fun and comparatively quick to play, will also involve playing around with sound.

INSTRUCTION MANUAL

Phase 1

Match the lights with corresponding button, three levels of increasing difficulty

Phase 2

Work out the answer to each equation and input the final digit of each into the pin pad once all figured out

Phase 3

Match the user’s tone to the original using three potentiometers

PROJECT TASK LIST

Plan Chart

Task Distribution

AdibulJamesRahul
Phase 3 Code and Testing
I2C Communication
Assembly
Phase 1 Code and Testing
Phase 2 Code and Testing
Production of box
Documentation
Assembly
Documentation
Design and CAD model of the box
Production of box
Assembly

Timeline

Week 9 – Discussed and chose our project
– Brainstormed possible ideas
– Discussed possible functions
– Created a design for the escape room.
– Created a low fidelity prototype of the design.
Week 10 – Ordered the components
– Completed phase 1 & 2 code
– Changed our design for phase 3
– Started with phase 3 code
– Started documentation and completed blog design
Week 11 – Design the exterior of escape room
– Created 3D CAD model of the design
– Started making the box for the escape room
– Completed phase 3 code
– Completed making the box for the escape room
– Connect phase 1 & 2 with 3 using I2C communication
Week 12 – Solder all parts
– Assemble and attach all parts onto the frame of the box

DESIGN CHOICES

Box Design:

For the box we decided to go for a triangle shape because our game consisted of 3 phases, so we thought triangle is best way to represent that.

For the material we chose MDF board because it is cost-effective and easily available while also being stable, durable and sustainable.

Additionally it is very consistent throughout, so the cut edges will appear smooth and won’t have voids or splinters.

We used square dowel sticks as the border for the front panel because it shows a really nice contrast between the rest of the box and the border while also partitioning all 3 phases.

Layout of the potentiometers and LEDs is in that particular way to reduce negative space in their respective partition.

Extra space for Phase 2 is given compared to Phase 1 & 3 not just because LCD screen and key pad require more phase, we wanted it to be the centre of focus. This is because LCD screen was planned to display hints for other phases as well.

Phase 1:

For this phase we decided to use LEDs, piezo element and buttons to create an interactive game because we believed LEDs work very as a visual cue for the user and buttons can work well as the user input. In this the user will have to match the sequence of blinking LEDs with the button of corresponding colour. Additionally we also used piezo element to produce different sounds for pressing the button, completing the levels and completing the entire phase. The sounds are really important to make the game more engaging and letting the user whether they have completed a level or the entire phase. Also at the end of each level and the entire phase all LEDs would start blinking. Finally to complete the first phase, user has to complete three levels of increased difficulty.

Phase 2:

For the second phase we decided to use a screen to display the equations and keypad for the user input. Being a escape room, how can we not put a puzzle which represents opening a safe. That’s exactly what were trying to go for with the keypad and screen. In this the user would be given four simple math equations on the screen and the last digit of each answer of the equations is the 4 digit code to reach next phase.

Phase 3:

In the last phase we decided to use the potentiometer as the user input and piezo element as the output. We went for potentiometers as the input because we wanted this phase to represent opening a vault kind of a puzzle where the user has to rotate a dial. For the output we went for piezo element, this works a audio cue for the user, this design decision was also backed by the market research which showed there are no available escape room puzzles in the marker with auditory cues. In this phase the user would have to match the music sequence consisting of 3 notes coming out of the piezo element which is random every time it is played, using the 3 potentiometers which work as dials. We also decided to keep different coloured LEDs to differentiate the sound provided to the user by the game and the ones they are testing. Additionally, we limited the range of frequencies provided in this level between 0Hz to 1000Hz to reduce the difficulty of this phase while also providing the user a bit of extra leverage by accepting the input plus or minus 50Hz to the original value given by the game as the correct answer. When all 3 notes are matched the user wins the game and it is represented by the blinking red and green lights in this phase.

MAKER MANUAL

Early Brainstorming

Low Fidelity Prototype

Production stages

  • Take a MDF piece and cut it according to the dimensions provided on the engineering drawing using a band saw
  • Sand uneven edges using disc sander
  • Attach the bottom triangle piece with two side pieces using hot glue
  • Drill holes of different dimensions(refer engineering drawing for dimensions) for the potentiometer, LEDs and buttons using hand drill
  • For the slot for the LCD screen drill a hole in 4 corners and cut the rectangle using a coping saw.
  • For the slot for the keypad wiring, drill onto to the two ends of the required slot and cut the piece using a coping saw.
  • Cut square dowel rods using a hand saw
  • Sand the imperfections using a disc sander
  • Stick the cut pieces on the edges of the existing frame as per the image using hot glue.
  • Solder all the parts and wires
  • Fit all the soldered parts(LEDs, potentiometer, buttons) in their respective slots
  • Reassemble the circuit with the soldered wire and parts
  • Put the LCD screen in its respective slot
  • Stick the keypad onto the wood
  • Place the front wooden panel in the box

Final Product

Dimensions and CAD Model

Engineering Drawing

Final Model

Phases 1, 2 & 3 (order is left to right on the panel)

Demo of Model

Parts used

Level 1 + 2:

  • 1 x Arduino Uno
  • 3×4 Keypad
  • 1 x Breadboard
  • 1 x Piezo Buzzer
  • 4 x LED’s (White, Blue, Red, Green)
  • 4 x Pushbuttons (White, Blue, Red, Green)
  • 4 x 10k Ohm Resistor
  • 4 x 560 Ohm Resistor
  • 39 x Wires

Level 3:

  • 1 x Arduino Uno
  • 1 x Breadboard
  • 1 x Piezo Buzzer
  • 3 x Potentiometer
  • 2 x 560 Ohm Resistor
  • 1 x 10k Ohm resistor
  • 2 x LEDs (Red and Green)
  • 14 x Wires

Connection for Arduinos (I2C):

  • 3 x Wires

Box:

  • MDF Board
  • Wooden Square Dowel Rods

Tools used

  • Hand Saw
  • Band Saw
  • Coping Saw
  • Hand Drill
  • Hot glue
  • Disc Sander

Breadboard Diagram

Recycle & Reuse

LCD screen and the Keypad we used for our final product was used from the box of reusable parts in the lab.

We reused square dowel rods which were put in the wood scraps in the maker space for the border of the front panel.

Shortcoming

  • In Phase 2 of the escape room, moving from input on the serial monitor to using the keypad was a struggle as the keypad is a new way to code. Some different iterations were made but the final working version is that the four equations are displayed and then the pin is inputted.
  • Where we wanted three levels, using one Arduino wouldn’t be enough for this due to the lack of pins. Therefore, we tried to use a multiplex to increase the amount of pins, this didn’t work. So therefore we have decided to go with using two Arduinos.
  • For the Phase 2, LCD screen didn’t work as planned. We tried to code the LCD screen in different ways but nothing seemed to work also with the help of the professor and demonstrators in the computer lab. Apparently there was a technical issue with the LCD screen provided and there wasn’t enough time to order a new one. So we had to shift everything which was supposed to display onto the LCD screen to the serial monitor, which primarily consisted of the equations for this phase and also we were planning to give hints for other phases that also couldn’t be done.
  • The buzzer in Phase 3 was very sensitive due to using potentiometers, we overcame this by allowing a range for the potentiometers to be in, instead of being exactly correct which was very hard to do. This allowed the user to complete the level as before it was nearly impossible due to the potentiometers changing value from any small knock.
  • Due to the time constraint we had to rush a lot of things which included the making of the final model, if we had more time to work on the final product it could have looked much better.

Code

Level 1 & 2

// Include Arduino Wire library for I2C
#include <Wire.h>

// Define Slave I2C Address
#define SLAVE_ADDR 9



//For level 1
int ledPin[4] = { 2, 3, 4, 5 };
int buttonPin[4] = { 8, 9, 10, 11 };

long randNumber;

int random1;
int random2;
int random3;
int random4;
int random5;

bool winlevelone;
bool winleveltwo;
bool winlevelthree;

int speakerPin = 12;  //speaker pin

int length = 2;
int lengthding = 3;
int lengthwin = 8;

char notes[] = { "ce" };
char notesding[] = { "bge" };
char noteswin[] = { "Cbagfedc" };

int beats[] = { 1, 1 };
int beatsding[] = { 1, 1, 1 };
int beatswin[] = { 1, 1, 1, 1, 1, 1, 1, 1 };

int tempo = 150;


//For level 2
int number1 = 10;
int number2 = 10;
int number3 = 10;
int number4 = 10;

bool wongame2;


#include <Keypad.h>

const byte ROWS = 4;  //four rows
const byte COLS = 3;  //four columns
//define the symbols on the buttons of the keypads

char hexaKeys[ROWS][COLS] = {
  { '1', '2', '3' },
  { '4', '5', '6' },
  { '7', '8', '9' },
  { '*', '0', '#' }
};
byte rowPins[ROWS] = { 7, 6, 13, A3 };  //connect to the row pinouts of the keypad
byte colPins[COLS] = { A2, A1, A0 };    //connect to the column pinouts of the keypad

//initialize an instance of class NewKeypad
Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);

int level2start = 0;

int click1 = 10;
int click2 = 10;
int click3 = 10;
int click4 = 10;

bool bclick1;
bool bclick2;
bool bclick3;
bool bclick4;



void setup() {
  Wire.begin();
  //for level 1
  Serial.begin(9600);
  randomSeed(analogRead(7));

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



void loop() {
  if (wongame2 == true) {
    //ADIBULS GAME

    // Write a charatre to the Slave
    Wire.beginTransmission(SLAVE_ADDR);
    Wire.write(5);
    Wire.endTransmission();
  
  }

  if (winlevelthree == true) {
    if (wongame2 == false) {
      game2();
      return (0);
    }
  }

  if (winlevelone == false) {
    gamestart1();
  }
  levelone();

  if (winlevelone == true) {
    gamestart2();
  }
  leveltwo();

  if (winleveltwo == true) {
    gamestart3();
  }
  levelthree();
}


void gamestart1() {
  randNumber = random(0, 4);
  //Serial.println(randNumber);
  random1 = randNumber;
  digitalWrite(ledPin[randNumber], HIGH);
  delay(400);
  digitalWrite(ledPin[randNumber], LOW);
  delay(200);
}


void levelone() {
  while (digitalRead(buttonPin[random1]) == HIGH) {
    waiting();
  }
  if (digitalRead(buttonPin[random1]) == LOW) {
    digitalWrite(ledPin[random1], HIGH);
    noise();
    delay(300);
    digitalWrite(ledPin[random1], LOW);
    winning();
    winlevelone = true;
  }
}


void gamestart2() {

  for (int i = 0; i < 3; i++) {
    randNumber = random(0, 4);
    //Serial.println(randNumber);
    if (i == 0) {
      random1 = randNumber;
    } else if (i == 1) {
      random2 = randNumber;
    } else {
      random3 = randNumber;
    }

    digitalWrite(ledPin[randNumber], HIGH);
    delay(400);
    digitalWrite(ledPin[randNumber], LOW);
    delay(200);
  }
}


void leveltwo() {

  while (digitalRead(buttonPin[random1]) == HIGH) {
    waiting();
  }

  if (digitalRead(buttonPin[random1]) == LOW) {
    digitalWrite(ledPin[random1], HIGH);
    noise();
    delay(300);
    digitalWrite(ledPin[random1], LOW);

    while (digitalRead(buttonPin[random2]) == HIGH) {
      waiting();
    }

    if (digitalRead(buttonPin[random2]) == LOW) {
      digitalWrite(ledPin[random2], HIGH);
      noise();
      delay(300);
      digitalWrite(ledPin[random2], LOW);

      while (digitalRead(buttonPin[random3]) == HIGH) {
        waiting();
      }

      if (digitalRead(buttonPin[random3]) == LOW) {
        digitalWrite(ledPin[random3], HIGH);
        noise();
        delay(300);
        digitalWrite(ledPin[random3], LOW);
        winning();
        winleveltwo = true;
      }
    }
  }
}


void gamestart3() {

  for (int i = 0; i < 5; i++) {
    randNumber = random(0, 4);
    //Serial.println(randNumber);
    if (i == 0) {
      random1 = randNumber;
    } else if (i == 1) {
      random2 = randNumber;
    } else if (i == 2) {
      random3 = randNumber;
    } else if (i == 3) {
      random4 = randNumber;
    } else {
      random5 = randNumber;
    }

    digitalWrite(ledPin[randNumber], HIGH);
    delay(400);
    digitalWrite(ledPin[randNumber], LOW);
    delay(200);
  }
}


void levelthree() {


  while (digitalRead(buttonPin[random1]) == HIGH) {
    waiting();
  }

  if (digitalRead(buttonPin[random1]) == LOW) {
    digitalWrite(ledPin[random1], HIGH);
    noise();
    delay(300);
    digitalWrite(ledPin[random1], LOW);

    while (digitalRead(buttonPin[random2]) == HIGH) {
      waiting();
    }

    if (digitalRead(buttonPin[random2]) == LOW) {
      digitalWrite(ledPin[random2], HIGH);
      noise();
      delay(300);
      digitalWrite(ledPin[random2], LOW);

      while (digitalRead(buttonPin[random3]) == HIGH) {
        waiting();
      }

      if (digitalRead(buttonPin[random3]) == LOW) {
        digitalWrite(ledPin[random3], HIGH);
        noise();
        delay(300);
        digitalWrite(ledPin[random3], LOW);

        while (digitalRead(buttonPin[random4]) == HIGH) {
          waiting();
        }

        if (digitalRead(buttonPin[random4]) == LOW) {
          digitalWrite(ledPin[random4], HIGH);
          noise();
          delay(300);
          digitalWrite(ledPin[random4], LOW);

          while (digitalRead(buttonPin[random5]) == HIGH) {
            waiting();
          }

          if (digitalRead(buttonPin[random5]) == LOW) {
            digitalWrite(ledPin[random5], HIGH);
            noise();
            delay(300);
            digitalWrite(ledPin[random5], LOW);
            winning2();
            winlevelthree = true;
          }
        }
      }
    }
  }
}


void waiting() {
  if (digitalRead(buttonPin[0]) == LOW) {
    digitalWrite(ledPin[0], HIGH);
  } else {
    digitalWrite(ledPin[0], LOW);
  }

  if (digitalRead(buttonPin[1]) == LOW) {
    digitalWrite(ledPin[1], HIGH);
  } else {
    digitalWrite(ledPin[1], LOW);
  }

  if (digitalRead(buttonPin[2]) == LOW) {
    digitalWrite(ledPin[2], HIGH);
  } else {
    digitalWrite(ledPin[2], LOW);
  }

  if (digitalRead(buttonPin[3]) == LOW) {
    digitalWrite(ledPin[3], HIGH);
  } else {
    digitalWrite(ledPin[3], LOW);
  }
}


void winning() {
  noiseding();
  for (int i = 0; i < 4; i++) {
    digitalWrite(ledPin[i], HIGH);
    delay(100);
  }
  delay(300);
  digitalWrite(ledPin[0], LOW);
  digitalWrite(ledPin[1], LOW);
  digitalWrite(ledPin[2], LOW);
  digitalWrite(ledPin[3], LOW);
  delay(300);
}


void winning2() {
  noisewin();
  noisewin();
  for (int i = 0; i < 3; i++) {
    for (int i = 0; i < 4; i++) {
      digitalWrite(ledPin[i], HIGH);
      delay(100);
    }
    for (int j = 0; j < 4; j++) {
      digitalWrite(ledPin[j], LOW);
      delay(100);
    }
  }
}


void playNote(char notewin, int durationwin) {
  char nameswin[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C' };
  int toneswin[] = { 1915, 1700, 1519, 1432, 1275, 1136, 1014, 956 };
  for (int i = 0; i < 8; i++) {
    if (nameswin[i] == notewin) {
      tone(speakerPin, toneswin[i], durationwin);
    }
  }
}


void noise() {
  for (int i = 0; i < length; i++) {
    if (notes[i] == ' ') {
      delay(beats[i] * tempo);
    } else {
      playNote(notes[i], beats[i] * tempo);
    }
    delay(tempo / 2);
  }
}

void noiseding() {
  for (int i = 0; i < lengthding; i++) {
    if (notesding[i] == ' ') {
      delay(beatsding[i] * tempo);
    } else {
      playNote(notesding[i], beatsding[i] * tempo);
    }
    delay(tempo / 2);
  }
}


void noisewin() {
  for (int i = 0; i < lengthwin; i++) {
    if (noteswin[i] == ' ') {
      delay(beatswin[i] * tempo);
    } else {
      playNote(noteswin[i], beatswin[i] * tempo);
    }
    delay(tempo / 2);
  }
}



void game2() {
  if (level2start == 0) {
    for (int i = 0; i < 4; i++) {
      if (number1 < 10) {
        if (number2 < 10) {
          if (number3 < 10) {
            if (number4 < 10) {
              winning();
            }
          }
        }
      }

      int num1 = random(5, 10);
      int num2 = random(1, 5);
      int num3 = random(1, 10);
      int answer = (num1 - num2) * num3;
      Serial.print("(");
      Serial.print(num1);
      Serial.print("-");
      Serial.print(num2);
      Serial.print(")");
      Serial.print("*");
      Serial.println(num3);

      if (i == 0) {
        number1 = answer % 10;
      }
      if (i == 1) {
        number2 = answer % 10;
      }
      if (i == 2) {
        number3 = answer % 10;
      }
      if (i == 3) {
        number4 = answer % 10;
      }

      //Serial.println(answer);
      // Serial.println(number1);
      // Serial.println(number2);
      // Serial.println(number3);
      // Serial.println(number4);
      delay(4000);
    }
    level2start = 1;
  }
  wingame2();
}


void wingame2() {
  level2start = 1;
  if (bclick1 == true) {
    if (bclick2 == true) {
      if (bclick3 == true) {
        if (bclick4 == true) {
          passwordenter();
        }
      }
    }
  }

  char customKey = customKeypad.getKey();
  if (customKey) {
    if (click1 == 10) {
      bclick1 = true;
      Serial.print("Pin 1 is = ");
      Serial.println(customKey);
      click1 = customKey;
      return (0);
    }
  }
  if (customKey) {
    if (click2 == 10) {
      bclick2 = true;
      Serial.print("Pin 2 is = ");
      Serial.println(customKey);
      click2 = customKey;
      return (0);
    }
  }
  if (customKey) {
    if (click3 == 10) {
      bclick3 = true;
      Serial.print("Pin 3 is = ");
      Serial.println(customKey);
      click3 = customKey;
      return (0);
    }
  }
  if (customKey) {
    if (click4 == 10) {
      bclick4 = true;
      Serial.print("Pin 4 is = ");
      Serial.println(customKey);
      click4 = customKey;
      return (0);
    }
  }
}

void passwordenter() {
  if (click1 - 48 == number1) {
    if (click2 - 48 == number2) {
      if (click3 - 48 == number3) {
        if (click4 - 48 == number4) {
          Serial.println("YAY YOU WIN");
          wongame2 = true;
          delay(2000);
        } else {
          Serial.println("TRY AGAIN PLEASE");
          bclick1 = false;
          bclick2 = false;
          bclick3 = false;
          bclick4 = false;
          click1 = 10;
          click2 = 10;
          click3 = 10;
          click4 = 10;
        }
      } else {
        Serial.println("TRY AGAIN PLEASE");
        bclick1 = false;
        bclick2 = false;
        bclick3 = false;
        bclick4 = false;
        click1 = 10;
        click2 = 10;
        click3 = 10;
        click4 = 10;
      }
    } else {
      Serial.println("TRY AGAIN PLEASE");
      bclick1 = false;
      bclick2 = false;
      bclick3 = false;
      bclick4 = false;
      click1 = 10;
      click2 = 10;
      click3 = 10;
      click4 = 10;
    }
  } else {
    Serial.println("TRY AGAIN PLEASE");
    bclick1 = false;
    bclick2 = false;
    bclick3 = false;
    bclick4 = false;
    click1 = 10;
    click2 = 10;
    click3 = 10;
    click4 = 10;
  }
}

Level 3

// Include Arduino Wire library for I2C
#include <Wire.h>

// Define Slave I2C Address
#define SLAVE_ADDR 9

int rd;

int ledPin = 3;
int ledPin2 = 4;
int answerTones[3];
int tones[3];
int speakerPin1 = 9;
int speakerPin2 = 10;
int length = 3;        // the number of notes
char notes[] = "cde";  // a space represents a rest
int beats[] = {4,4,1};
int tempo = 800;
int sensorPins[] = {A3,A2,A1};                    // select the input pins for the potentiometers
int sensorValues[3];  // variables to store the value coming from the sensor

void setup() {
  // Initialize I2C communications as Slave
  Wire.begin(SLAVE_ADDR);
  
  // Function to run when data received from master
  Wire.onReceive(receiveEvent);
  
  randomSeed(analogRead(8));
  Serial.begin(9600);
  pinMode(speakerPin1, OUTPUT);
  pinMode(speakerPin2, OUTPUT);
  pinMode(ledPin, OUTPUT);
  pinMode(ledPin2, OUTPUT);
  for (int i = 0; i < length; i++) {
    tones[i] =  random(0,1000);
  }
}

void loop() {
  // read the value from the sensor:
Serial.println(rd);
 if (rd == 5){
    for (int i = 0; i < length; i++) {
      answerTones[i] = map(analogRead(sensorPins[i]), 0, 1023, 0, 1000);
      
    }
    // Serial.println(answerTones[0]);
    // Serial.println(answerTones[1]);
    // Serial.println(answerTones[2]);
    playMelody();

    delay(3000);
    playMelody2();

    delay(3000);

    if (answerTones[0] < tones[0]-25 || answerTones[0] > tones[0]+25) {
      Serial.println("Error: Unexpected sensor reading for tone 0");
    }
    if ((answerTones[0] > tones[0]-25) && (answerTones[0] < tones[0]+25)) {
      Serial.println("expected sensor reading for tone 0");
      if ((answerTones[1] > tones[1]-25) && (answerTones[1] < tones[1]+25)) {
        Serial.println("expected sensor reading for tone 1");
        if ((answerTones[2] > tones[2]-25) && (answerTones[2] < tones[2]+25)) {
          Serial.println("YOU WIN!!");
          for (int i = 0; i < 7; i++){
            wingame();
          }
          delay(2000000000000);
        }
      }
    }
 }
}

void playNote(char note, int duration) {
  char names[] = { 'c', 'd', 'e' };

  // play the tone corresponding to the note name
  for (int i = 0; i < 3; i++) {
    if (names[i] == note) {
      tone(speakerPin1, tones[i], duration);
    }
  }
}

void playMelody() {
  digitalWrite(ledPin, LOW);
  digitalWrite(ledPin2, HIGH);
  for (int i = 0; i < length; i++) {
    // Serial.println(tones[i]);
    if (notes[i] == ' ') {
      delay(beats[i] * tempo);  // rest
    } else {
      playNote(notes[i], beats[i] * tempo);
    }
    Serial.println(tones[i]);
    // pause between notes
    delay(tempo / 2);
  }
}


void playNote2(char note, int duration) {
  char names[] = { 'c', 'd', 'e' };
  int tones[] = { answerTones[0], answerTones[1], answerTones[2]};
  //play the tone corresponding to the note name
  for (int i = 0; i < 3; i++) {
    if (names[i] == note) {
      tone(speakerPin1, tones[i], duration);
    }
  }
}

void playMelody2() {
  digitalWrite(ledPin, HIGH);
  digitalWrite(ledPin2, LOW);
  for (int i = 0; i < length; i++) {
    if (notes[i] == ' ') {
      delay(beats[i] * tempo);  // rest
    } else {
      playNote2(notes[i], beats[i] * tempo);
    }
    Serial.println(answerTones[i]);

    // pause between notes
    delay(tempo / 2);
  }
}

void wingame() { 
  digitalWrite(ledPin, HIGH);
  digitalWrite(ledPin2, HIGH);
  delay(250);
  digitalWrite(ledPin,LOW);
  digitalWrite(ledPin2, LOW);
  delay(250);
  digitalWrite(ledPin, HIGH);
  digitalWrite(ledPin2, HIGH);
  delay(250);
  digitalWrite(ledPin,LOW);
  digitalWrite(ledPin2, LOW);
  delay(250);
  digitalWrite(ledPin, HIGH);
  digitalWrite(ledPin2, HIGH);
  delay(250);
  digitalWrite(ledPin,LOW);
  digitalWrite(ledPin2, LOW);
  delay(250);
  digitalWrite(ledPin, HIGH);
  digitalWrite(ledPin2, HIGH);
}


void receiveEvent() {
  // read one character from the I2C
  rd = Wire.read();
  // Print value of incoming data
  Serial.println(rd);
    
}