Final Project: Smash Your Memory [User Testing]

IDEA:

I would have the pads laid on the floor and use longer wires to create a bigger space.

user testing:

THINGS TO WORK ON 

  1. User testing feedback
    1. shorten the melody line
    2. allow players to practice and familiarize the notes
  2. Display ranking
  3. Aesthetics and physical decorations
    1. wooden box to contain the breadboard and Arduino Uno
    2. square pieces to package the pads
//Processing codes

/*
 1. fix the melody
 2. display ranking
 3. aesthetics and physical decoration
 */

/*
 name: Chi-Ting Tsai
 assignment: final project
 date: 12/07/2021
 "Smash Your Memory"
 */

import processing.sound.*;
SoundFile demoMelody;
SoundFile recC;
SoundFile recD;
SoundFile recE;
SoundFile recG;
SoundFile recA;

int size = 200;
color frame = color(237, 168, 17);

int stage = 0;
int noteC = 1;
int noteD = 2;
int noteE = 3;
int noteG = 5;
int noteA = 6;
int[] correctMelody = {noteD, noteC, noteE, noteD, noteG, noteA, noteG, noteE, noteD, noteC};


void setup() {
  size (1024, 768);
  printArray(Serial.list());
  String portname=Serial.list()[3];
  println(portname);
  myPort = new Serial(this, portname, 9600);
  myPort.clear();
  myPort.bufferUntil('\n');
  demoMelody = new SoundFile (this, "/Users/chi-tingtsai/Downloads/10.wav");
  recC = new SoundFile (this, "/Users/chi-tingtsai/Downloads/C.wav");
  recD = new SoundFile (this, "/Users/chi-tingtsai/Downloads/D.wav");
  recE = new SoundFile (this, "/Users/chi-tingtsai/Downloads/E.wav");
  recG = new SoundFile (this, "/Users/chi-tingtsai/Downloads/G.wav");
  recA = new SoundFile (this, "/Users/chi-tingtsai/Downloads/A.wav");
}

void draw() {
  if (stage == 0) {
    ranking();
  } else if (stage == 1) {
    rules();
  } else if (stage == 2) {
    game();
  } else if (stage == 3) {
    lose();
  } else if (stage ==4) {
    win();
  }
}

//display ranking
void ranking() {
  background(color(99, 144, 130));
  PFont F = createFont("PatuaOne-Regular", 1);
  fill(255);
  textAlign(CENTER);

  //Game title
  textFont(F, 50);
  text("Smash Your Memory", width/2, height/2-50);
  //explain how to start
  textFont(F, 30);
  text("Smash Covid to Begin Game", width/2, height*3/4);

  //frame
  noStroke();
  rectMode(CENTER);
  fill(frame);
  rect(width/2, 10, width, 20);
  rect(width/2, height-10, width, 20);
  rect(10, height/2, 20, height);
  rect(width-10, height/2, 20, height);
}

void rules() {
  background(color(99, 144, 130));
  PFont F = createFont("PatuaOne-Regular", 1);
  fill(255);
  textAlign(CENTER);

  //explain how to play
  textFont(F, 50);
  text("RULES", width/2, height/4);
  textFont(F, 30);
  text("Listen to the pentatonic melody played after this scene.\n It's only going to play once!\n Smash the corresponding pads to recreate the melody!\nC: COVID\nD: Deadlines\nE: course Enrollment\nG: GPA\nA: Anxiety", width/2, height/2-120);
  textFont(F, 30);
  text("Smash course Enrollment to listen to the melody and begin!", width/2, height-110);

  //frame
  noStroke();
  rectMode(CENTER);
  fill(frame);
  rect(width/2, 10, width, 20);
  rect(width/2, height-10, width, 20);
  rect(10, height/2, 20, height);
  rect(width-10, height/2, 20, height);
}

import processing.serial.*;
Serial myPort;

int aSignal = 0;
int prevASignal = 3;
int val = 0;

void game() {
  //background
   background(color(99, 144, 130));
  fill(255);
  PFont F = createFont("PatuaOne-Regular", 1);
  textAlign(CENTER);

  textFont(F, 50);
  text("Listen Carefully and Recreate!", width/2, height/2-50);
}

void serialEvent(Serial myPort) {
  String s=myPort.readStringUntil('\n');
  s=trim(s);
  if (s!= null) {
    aSignal = parseInt(s);
    //println("signal from arduino: " + s);
    //scene transition
    if (stage == 0 && aSignal == noteC) {
      recC.play();
      stage = 1;
    }
    //if (stage == 1 && aSignal == noteD) {
    //  demoMelody.play();
    //}
    if (stage == 1 && aSignal == noteE) {
      stage = 2;
      demoMelody.play();
    }
    if ((stage == 3 || stage == 4) && aSignal == noteG) {
      recG.play();
      stage = 0;
    }

    //note playing and verification
    if (stage == 2 && prevASignal!= aSignal) {
      println("number stored in the array: " + aSignal);
      if (aSignal == noteC) {
        recC.play();
      } else if (aSignal == noteD) {
        recD.play();
      } else if (aSignal == noteE) {
        recE.play();
      } else if (aSignal == noteG) {
        recG.play();
      } else if (aSignal == noteA) {
        recA.play();
      }
      //verify note in array
      if (correctMelody[val] == aSignal) {
        //change circle color
        val++;
        prevASignal = aSignal;
        if (val == 10) {
          stage = 4;
        }
      } else {
        //change circle color
        delay(5000);
        stage = 3;
      }
    }
  }
  myPort.write('\n');
}

void lose() {
  background(color(99, 144, 130));
  PFont F = createFont("PatuaOne-Regular", 1);
  noStroke();
  fill(255);
  
  textFont(F, 80);
  text("Not the right note!", width/2, height/2);
  textFont(F, 50);
  text("Awwww... Smash GPA to see your ranking and restart.", width/2, height/2+50);
}

void win() {
  background(color(99, 144, 130));
  PFont F = createFont("PatuaOne-Regular", 1);
  noStroke();
  fill(255);

  textFont(F, 80);
  text("Congratulations! You have done it!", width/2, height/2);
  textFont(F, 50);
  text("Have you found your peace by smashing those that give off negative energy?", width/2, height/2-50);
  textFont(F, 30);
  text("Smash GPA to see your ranking", width/2, height/2+50);
}
//Arduino codes

//variable declaration
const int C = 1;
const int D = 2;
const int E = 3;
const int G = 5;
const int A = 6;
const int in_C = 2;
const int in_D = 3;
const int in_E = 4;
const int in_G = 5;
const int in_A = 6;
const int speaker_Pin = 8;
const int led_C = 9;
const int led_D = 10;
const int led_E = 11;
const int led_G = 12;
const int led_A = 13;

int switch_C, switch_D, switch_E, switch_G, switch_A = 0;

int smash = 0;

void setup() {
  // put your setup code here, to run once:
  pinMode(in_C, INPUT);
  pinMode(in_D, INPUT);
  pinMode(in_E, INPUT);
  pinMode(in_G, INPUT);
  pinMode(in_A, INPUT);
  pinMode(speaker_Pin, OUTPUT);
  pinMode(led_C, OUTPUT);
  pinMode(led_D, OUTPUT);
  pinMode(led_E, OUTPUT);
  pinMode(led_G, OUTPUT);
  pinMode(led_A, OUTPUT);

  Serial.begin(9600);
  Serial.println("0");
}

void loop() {
  // put your main code here, to run repeatedly:
  switch_C = digitalRead(in_C);
  switch_D = digitalRead(in_D);
  switch_E = digitalRead(in_E);
  switch_G = digitalRead(in_G);
  switch_A = digitalRead(in_A);

  while (Serial.available()) {
    if (Serial.read() == '\n') {
      //Note C
      if (switch_C == 1) {                //released, if the two aluminum foils touch
        digitalWrite(led_C, HIGH);        //turns on LED
        smash = C;
      }
      else if (switch_C && switch_D && switch_E && switch_G && switch_A == 0)
      { //released, if the two aluminum foils part
        digitalWrite (led_C, LOW);        //turns off LED
        smash = 0;
      };

      //Note D
      if (switch_D == 1) {                //released, if the two aluminum foils touch
        digitalWrite(led_D, HIGH);        //turns on LED
        smash = D;
      }
      else if (switch_C && switch_D && switch_E && switch_G && switch_A == 0)
      { //released, if the two aluminum foils part
        digitalWrite (led_D, LOW);        //turns off LED
        smash = 0;
      };

      //Note E
      if (switch_E == 1) {                //released, if the two aluminum foils touch
        digitalWrite(led_E, HIGH);        //turns on LED
        smash = E;
      }
      else if (switch_C && switch_D && switch_E && switch_G && switch_A == 0)
      { //released, if the two aluminum foils part
        digitalWrite (led_E, LOW);        //turns off LED
        smash = 0;
      };

      //Note G
      if (switch_G == 1) {                //released, if the two aluminum foils touch
        digitalWrite(led_G, HIGH);        //turns on LED
        smash = G;
      }
      else if (switch_C && switch_D && switch_E && switch_G && switch_A == 0)
      { //released, if the two aluminum foils part
        digitalWrite (led_G, LOW);        //turns off LED
        smash = 0;
      };

      //Note A
      if (switch_A == 1) {                //released, if the two aluminum foils touch
        digitalWrite(led_A, HIGH);        //turns on LED
        smash = A;
      }
      else if (switch_C && switch_D && switch_E && switch_G && switch_A == 0)
      { //released, if the two aluminum foils part
        digitalWrite (led_A, LOW);        //turns off LED
        smash = 0;
      }
      Serial.println(smash);
    }
  }
  //  Serial.print("smash: ");
  //  Serial.println(smash);
  //  Serial.print("C: ");
  //  Serial.println(switch_C);
  //  Serial.print("D: ");
  //  Serial.println(smash);
  //  Serial.print("E: ");
  //  Serial.println(smash);
  //  Serial.print("G: ");
  //  Serial.println(smash);
  //  Serial.print("A: ");
  //  Serial.println(smash);
}

Leave a Reply