Simon Game - Xylophone Version

1,747

13

6

Introduction: Simon Game - Xylophone Version

About: Antonio Gomes received a Bachelor’s of Computer Science as well as a Bachelor of Communication and Multimedia Design from Coimbra Polytechnic Institute. He is an inventor of shape changing composites, actuat...

A little game interface I'm making..in essence, it will be the simon game....except much harder and xylophone style :)

(For those who don't know, simon game is the following:
http://www.youtube.com/watch?v=4YhVyt4q5HI)

Materials / tools are pretty straight forward...

I used a laser cutter but you can do it manually
Plywood
Acrylic
Arduino UNO
8 Piezo Sensors
8 LEDS

Temporary code has been implemented, missing sound but that will come soon enough

Quick video, day and night 
http://www.youtube.com/watch?v=ZcibT5wFgy4&feature=youtu.be

NOTE: Unless you feel comfortably with coding and playing around with different resistor, I would avise to make this in a larger scale!
Great example: https://www.instructables.com/id/Arduino-Xylophone/ by @audreyobscura


[code]
const int buttonSensor = A5;

int led1 = 5; //LED pins
int led2 = 4;
int led3 = 3;
int led4 = 2;
int turn = 0;
int inputRead = 0;
/*int input2 = LOW;
int input3 = LOW;
int input4 = LOW;*/

int randomArray[50]; //Intentionally long to store up to 100 inputs (doubtful anyone will get this far)
int inputArray[50];


void setup() {

  Serial.begin(9600);

  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
  pinMode(led4, OUTPUT);


  randomSeed(analogRead(0)); //Added to generate "more randomness" with the randomArray for the output function

for (int y=0; y<=99; y++){ //For statement to loop through the output and input functions
   output();
   input();
}

   }

void loop() { //Unused void loop(), though for some reason it doesn't compile without this /shrug

}

void output() { //function for generating the array to be matched by the player

   for (int y=turn; y <= turn; y++){ //Limited by the turn 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 turn count
    for (int x=0; x <= turn; x++){

      Serial.print(randomArray[x]);

      if (randomArray[x]
== 1) {  //if statements to display the stored values in the array
       digitalWrite(led1, HIGH);
        delay(500);
        digitalWrite(led1, LOW);
        delay(100);
      }

      if (randomArray[x]
== 2) {
       digitalWrite(led2, HIGH);
        delay(500);
        digitalWrite(led2, LOW);
        delay(100);
      }

      if (randomArray[x]
== 3) {
       digitalWrite(led3, HIGH);
        delay(500);
        digitalWrite(led3, LOW);
        delay(100);
      }

      if (randomArray[x]
== 4) {
       digitalWrite(led4, HIGH);
        delay(500);
        digitalWrite(led4, LOW);
        delay(100);
      }
     }
    }
   }



void input() { //Function for allowing user input and checking input against the generated array



  for (int x=0; x <= turn;){ //Statement controlled by turn count
    /*input1 = digitalRead(switch1);
    input2 = digitalRead(switch2);
    input3 = digitalRead(switch3);
    input4 = digitalRead(switch4);*/

    inputRead = analogRead(buttonSensor);
    //Serial.println(inputRead);
    delay(100);


    if (inputRead > 685){ //Checking for button push
      digitalWrite(led1, HIGH);
      //playTone(1915, 200);//Passes tone value and duration of the tone to the playTone function
      delay(200);
      digitalWrite(led1, LOW);
      inputArray[x] = 1;
      delay(50);
      Serial.print(" ");
      Serial.print(1);
      if (inputArray[x] != randomArray[x]) { //Checks value input by user and checks it against
        fail();                              //the value in the same spot on the generated array
      }                                      //The fail function is called if it does not match
      x++;
    }

    if ((inputRead > 600) && (inputRead <680)){
      digitalWrite(led2, HIGH);
      delay(200);
      digitalWrite(led2, LOW);
      inputArray[x]
= 2;
     delay(50);
      Serial.print(" ");
      Serial.print(2);
      if (inputArray[x]
!= randomArray[x]
) {
       fail();
      }
      x++;

    }

    if ((inputRead > 535) && (inputRead <590)){
      digitalWrite(led3, HIGH);
      delay(200);
      digitalWrite(led3, LOW);
      inputArray[x]
= 3;
     delay(50);
      Serial.print(" ");
      Serial.print(3);
      if (inputArray[x]
!= randomArray[x]
) {
       fail();
      }
      x++;

    }

    if ((inputRead > 400) && (inputRead <525)){

      digitalWrite(led4, HIGH);
      delay(200);
      digitalWrite(led4, LOW);
      inputArray[x]
= 4;
     delay(50);
      Serial.print(" ");
      Serial.print(4);
      if (inputArray[x]
!= randomArray[x]
) {
       fail();

       Serial.print("failed");
      }
      x++;

    }

   }
  delay(500);
  turn++; //Increments the turn count, also the last action before starting the output function over again
}

void fail() { //Function used if the player fails to match the sequence

  for (int y=0; y<=5; y++){ //Flashes lights for failure
   digitalWrite(led1, HIGH);
   digitalWrite(led2, HIGH);
   digitalWrite(led3, HIGH);
   digitalWrite(led4, HIGH);
   delay(200);
   digitalWrite(led1, LOW);
   digitalWrite(led2, LOW);
   digitalWrite(led3, LOW);
   digitalWrite(led4, LOW);
   delay(200);
  }
  delay(500);
  turn = -1; //Resets turn value so the game starts over without need for a reset button
}[/code]

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Instructables Design Competition

Participated in the
Instructables Design Competition

DIY Audio

Participated in the
DIY Audio

Be the First to Share

    Recommendations

    • Finish It Already Speed Challenge

      Finish It Already Speed Challenge
    • Arduino Contest 2020

      Arduino Contest 2020
    • First Time Author Contest

      First Time Author Contest

    6 Discussions

    0
    agomes6
    agomes6

    Reply 7 years ago on Introduction

    I am still working on this but it's shaping up :

    http://www.youtube.com/watch?v=ZcibT5wFgy4&feature=youtu.be

    0
    amandaghassaei
    amandaghassaei

    Reply 7 years ago on Introduction

    cool, looks like you might need to isolate the keys from nearby vibrations a little more?

    0
    agomes6
    agomes6

    Reply 7 years ago on Introduction

    threshold was at [8]={50...50} even though I am using different resistor for better differentiation....that's just code, I was just thrilled to share the video with you but as soon as the time allows it i will polish it up...with the simon game on. But for anyone replicating this, i would most definitely advise to make it on a larger scale!! There's a really good xylophone arduino from one of the instructables staff ;)

    0
    amandaghassaei
    amandaghassaei

    Reply 7 years ago on Introduction

    I was talking more about vibration dampening, using rubber underneath the keys to isolate them. But yeah maybe increasing the threshold would help too