A. PROJECT TITLE
Music Drop Tower — by Sophia Wan & Nadine Chen
Instructor: Eric Parren
B. CONTEXT AND SIGNIFICANCE
In the previous project that I researched called 21 Swings at Place des Arts, we found the interaction and cooperation between players interesting. Players have to swing to the same height to make unique sounds together. The theory behind our project is quite similar to this project. Our project requires the two players to find one note on each of their sides to light on 3 LEDs. If they choose to play the game separately, they can only light on no more than 3 LEDs of the heart. However, by working together, the result will be the 6 LEDs embedded around the heart lit on at the same time. 21 Swings at Place des Arts reminds us of how fun and interactive it is as a two-player job asking both to contribute so that the result can be different. For us, it seems to be important that cooperation makes difference and makes both of the players feel a sense of accomplishment. I believe whoever is strangers or friends can play this game together. If you are playing with a stranger, you may find it fun to collaborate with someone you don’t know and it will be a good chance to make a friend. If you’re playing with your friend, it will be interesting to figure out how to light on all the LEDs together as fast as you can, with your understanding of each other.
C. CONCEPTION AND DESIGN
In the beginning, we made it a competitive game. Each player has to find two notes which can light on the LED out of the total seven notes on their side. Once a player finds both of the two notes, there will be a melody which means the player wins. We only had two LEDs and two buzzers for the two sides. However, after the user testing session, we found the game less interesting if the two players play separately. Therefore, we tried to change our game to something requiring collaboration. This is why we drew a heart and then built six LEDs around it. Lighting the 3 LEDs on both sides in order to make it a complete heart is more interesting.
We made the mechanism a two-tower craft because our initial aim was to make it a competitive game. By making these two towers, two players can’t see what each other is doing and this structure reminds them that it’s a competition. In addition, we applied the ultrasonic sensors and to change the distance/note we used a small piece of the cupboard, attaching it with chopsticks so that people can slide up and down. We considered buttons at first but they are so fixed and don’t fit the ultrasonic sensor well. The cupboards can be cut to the exact size we want to intervene the ultrasonic sensor and it’s more flexible as people can slide it around to make different sounds. The buzzers are very easy to control and make a melody as we can find related codes in the examples of Arduino.
D. FABRICATION AND PRODUCTION
My group member and I discussed the proposal together. We tried to find something practical and interesting to play with. Here is our sketch of the craft.
Besides our meeting to discuss the proposal, we contacted the LAs to make sure the theme we choose and the proposal are practical and feasible. The theme was music and game. The most important and impressive part was the codes. The circuits and crafts were relatively easy to build. However, for the part of the code, as we’re not familiar with many functions, we seek help from professors, LAs and fellows. Finally, we reached the goal. It was hard to set the timing for the duration that LEDs are lit. We used the millisecond function which we learned during class but it can’t stop timing, which didn’t meet our need to start timing each time when we change the height of the cupboard. Thus, our professor Eric taught us to use “bool” to set timing accurately.
Here is the circuit we built. From https://www.arduino.cc/
The materials we used include:
- ultrasonic sensor*2
- LED*6
- buzzer*2
- breadboard*2
- Arduino Uno*2
- cupboards
In the user testing session, we received many useful and meaningful suggestions. Sylvia told us it would be nice to change the melody of one buzzer, in order to help the other player better identify who wins. Also, she advised us to set the notes to random ones each time the game restarts. With her help, we changed the codes to set those notes to random ones so that players can play the game again and again. Besides, we noticed that there will be more fun if it’s a collaborative game. So we drew a heart in the middle and built LEDs around it. There is one random note out of the total seven notes to light on the three LEDs on your side, however, they are only half of the heart. To light the whole heart, two players have to work together. In this way, losing or winning is not important anymore because even if you find the note which can light on all the LEDs on your side, you can’t see the whole heart lit by six LEDs.
This is the photo of our project BEFORE the user-testing session:
These are the recordings of our project AFTER the user-testing session:
Work-in-progress:
Final version:
Codes reference:
https://www.arduino.cc/en/Tutorial/BuiltInExamples/Blink
https://www.arduino.cc/en/Tutorial/BuiltInExamples/toneKeyboard
https://www.tutorialspoint.com/arduino/arduino_ultrasonic_sensor.htm
Below are the codes:
#include “pitches.h”
const int trigPin = 9;
const int echoPin = 10;
const int buzzer1 = 8;
// defines variables
long duration;
int distance;
long value1;
float SMOOTHING = 0.9;
float smoothed;
float startTime = -1;
bool isPlayingNote1 = false;
bool isPlayingNote2 = false;
bool isPlayingNote3 = false;
bool isPlayingNote4 = false;
bool isPlayingNote5 = false;
bool isPlayingNote6 = false;
bool isPlayingNote7 = false;
//long startTimee = 0;
const int yellowled = 12;
const int greenled = 13;
const int redled = 7;
int twotimes = 0;
int chosenNote1;
int chosenNote2;
bool hasHitNote1 = false;
bool hasHitNote2 = false;
int melody[] = {
NOTE_A3, NOTE_D3, NOTE_G3, NOTE_AS3, 0, NOTE_B3, NOTE_B3, NOTE_B3, NOTE_C4
};
// note durations: 4 = quarter note, 8 = eighth note, etc.:
int noteDurations[] = {
4, 8, 8, 4, 4, 8, 8, 8, 4
};
// int test = 999;
void setup() {
Serial.begin(9600); // Starts the serial communication
pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an Input
pinMode(buzzer1, OUTPUT);
pinMode(yellowled, OUTPUT);
pinMode(greenled, OUTPUT);
pinMode(redled, OUTPUT);
// initialize the digital pin as an output.
randomSeed(analogRead(A5));
for (int i = 0; i < 100; i++) {
int r = random(100);
}
chosenNote1 = random(1, 8);
chosenNote2 = random(1, 8);
Serial.print(“first note chosen:”);
Serial.print(chosenNote1);
Serial.print(“,”);
Serial.println(chosenNote2);
}
void loop() {
// Clears the trigPin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(echoPin, HIGH);
// Calculating the distance
distance = duration * 0.034 / 2;
// Prints the distance on the Serial Monitor
// Serial.print(“Distance: “);
// Serial.println(distance);
smoothed = smoothed * (1.0 – SMOOTHING) + distance * SMOOTHING;
// Serial.println(smoothed);
if (smoothed < 5) { //Note 1
isPlayingNote2 = false;
isPlayingNote3 = false;
isPlayingNote4 = false;
isPlayingNote5 = false;
isPlayingNote6 = false;
isPlayingNote7 = false;
if (isPlayingNote1 == false) {
startTime = millis();
isPlayingNote1 = true;
tone(8, 392);
if (chosenNote1 == 1) {
digitalWrite(LED_BUILTIN, HIGH);
delay(500);
digitalWrite(LED_BUILTIN, LOW);
hasHitNote1 = true;
} else if (chosenNote2 == 1) {
digitalWrite(LED_BUILTIN, HIGH);
delay(500);
digitalWrite(LED_BUILTIN, LOW);
hasHitNote2 = true;
}
}
} else if (smoothed < 13) { //Note 2
isPlayingNote1 = false;
isPlayingNote3 = false;
isPlayingNote4 = false;
isPlayingNote5 = false;
isPlayingNote6 = false;
isPlayingNote7 = false;
if (isPlayingNote2 == false) {
startTime = millis();
isPlayingNote2 = true;
tone(8, 440);
if (chosenNote1 == 2) {
digitalWrite(greenled, HIGH);
delay(500);
digitalWrite(greenled, LOW);
hasHitNote1 = true;
} else if (chosenNote2 == 2) {
digitalWrite(greenled, HIGH);
delay(500);
digitalWrite(greenled, LOW);
hasHitNote2 = true;
}
/*
if (millis() – startTimee < 1000) {
if (millis() % 1000 < 500) {
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
} else { // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
}
} else {
digitalWrite(LED_BUILTIN, LOW);
} // wait for a second
*/
}
} else if (smoothed < 18) { //Note3
isPlayingNote1 = false;
isPlayingNote2 = false;
isPlayingNote4 = false;
isPlayingNote5 = false;
isPlayingNote6 = false;
isPlayingNote7 = false;
if (isPlayingNote3 == false) {
startTime = millis();
isPlayingNote3 = true;
tone(8, 500);
if (chosenNote1 == 3) {
digitalWrite(LED_BUILTIN, HIGH);
delay(500);
digitalWrite(LED_BUILTIN, LOW);
hasHitNote1 = true;
} else if (chosenNote2 == 3) {
digitalWrite(LED_BUILTIN, HIGH);
delay(500);
digitalWrite(LED_BUILTIN, LOW);
hasHitNote2 = true;
}
}
} else if (smoothed < 24) { //Note4
isPlayingNote1 = false;
isPlayingNote2 = false;
isPlayingNote3 = false;
isPlayingNote5 = false;
isPlayingNote6 = false;
isPlayingNote7 = false;
if (isPlayingNote4 == false) {
startTime = millis();
isPlayingNote4 = true;
tone(8, 520);
if (chosenNote1 == 4) {
digitalWrite(LED_BUILTIN, HIGH);
delay(500);
digitalWrite(LED_BUILTIN, LOW);
hasHitNote1 = true;
} else if (chosenNote2 == 4) {
digitalWrite(LED_BUILTIN, HIGH);
delay(500);
digitalWrite(LED_BUILTIN, LOW);
hasHitNote2 = true;
}
}
} else if (smoothed < 30) { //Note5
isPlayingNote1 = false;
isPlayingNote2 = false;
isPlayingNote3 = false;
isPlayingNote4 = false;
isPlayingNote6 = false;
isPlayingNote7 = false;
if (isPlayingNote5 == false) {
startTime = millis();
isPlayingNote5 = true;
tone(8, 580);
if (chosenNote1 == 5) {
digitalWrite(LED_BUILTIN, HIGH);
delay(500);
digitalWrite(LED_BUILTIN, LOW);
hasHitNote1 = true;
} else if (chosenNote2 == 5) {
digitalWrite(LED_BUILTIN, HIGH);
delay(500);
digitalWrite(LED_BUILTIN, LOW);
hasHitNote2 = true;
}
}
} else if (smoothed < 37) { //Note6
isPlayingNote1 = false;
isPlayingNote2 = false;
isPlayingNote3 = false;
isPlayingNote4 = false;
isPlayingNote5 = false;
isPlayingNote7 = false;
if (isPlayingNote6 == false) {
startTime = millis();
isPlayingNote6 = true;
tone(8, 660);
if (chosenNote1 == 6) {
digitalWrite(LED_BUILTIN, HIGH);
delay(500);
digitalWrite(LED_BUILTIN, LOW);
hasHitNote1 = true;
} else if (chosenNote2 == 6) {
digitalWrite(LED_BUILTIN, HIGH);
delay(500);
digitalWrite(LED_BUILTIN, LOW);
hasHitNote2 = true;
}
}
} else if (smoothed < 40) { //Note7
isPlayingNote1 = false;
isPlayingNote2 = false;
isPlayingNote3 = false;
isPlayingNote4 = false;
isPlayingNote5 = false;
isPlayingNote6 = false;
if (isPlayingNote7 == false) {
startTime = millis();
isPlayingNote7 = true;
tone(8, 720);
if (chosenNote1 == 7) {
digitalWrite(LED_BUILTIN, HIGH);
delay(500);
digitalWrite(LED_BUILTIN, LOW);
hasHitNote1 = true;
} else if (chosenNote2 == 7) {
digitalWrite(LED_BUILTIN, HIGH);
delay(500);
digitalWrite(LED_BUILTIN, LOW);
hasHitNote2 = true;
}
}
}
if (millis() – startTime > 1000 && isPlayingNote1 == true) {
noTone(8);
}
if (millis() – startTime > 1000 && isPlayingNote2 == true) {
noTone(8);
}
if (millis() – startTime > 1000 && isPlayingNote3 == true) {
noTone(8);
}
if (millis() – startTime > 1000 && isPlayingNote4 == true) {
noTone(8);
}
if (millis() – startTime > 1000 && isPlayingNote5 == true) {
noTone(8);
}
if (millis() – startTime > 1000 && isPlayingNote6 == true) {
noTone(8);
}
if (millis() – startTime > 1000 && isPlayingNote7 == true) {
noTone(8);
}
if (hasHitNote1 == true && hasHitNote2 == true) {
Serial.println(“both notes are correct”);
noTone(8);
digitalWrite(greenled, HIGH);
digitalWrite(yellowled, HIGH);
digitalWrite(redled, HIGH);
Serial.println(“yellow led will be on”);
for (int thisNote = 0; thisNote < 9; thisNote++) {
int noteDuration = 800 / noteDurations[thisNote];
tone(8, melody[thisNote], noteDuration);
int pauseBetweenNotes = noteDuration * 1.30;
delay(pauseBetweenNotes);
noTone(8);
}
delay(3000); // wait for 3 seconds before restarting
hasHitNote1 = false;
hasHitNote2 = false;
chosenNote1 = random(1, 8);
chosenNote2 = random(1, 8);
Serial.print(“notes chosen”);
Serial.print(chosenNote1);
Serial.print(“,”);
Serial.println(chosenNote2);
digitalWrite(greenled, LOW);
digitalWrite(yellowled, LOW);
digitalWrite(redled, LOW);
}
// if (millis() – startTime < 1000) {
// if (millis() % 800 < 400) {
// digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
// } else { // wait for a second
// digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
// }
// } else {
// digitalWrite(LED_BUILTIN, LOW);
// } // wait for a second
// if (smoothed = 3) {
// startTime = millis();
// if (startTime != -1) {
// tone(8, 392);
// delay(1000);
// noTone(8);
// }
// } else {
// noTone(8);
// startTime = -1;
// }
// // else if (millis() > 1500) {
// // noTone(8);
// // }
// if (smoothed < 35.1 && smoothed > 34.9) {
// startTime = millis();
// }
// if (startTime != -1) {
// tone(8, 392);
// delay(1000);
// noTone(8);
// } else {
// noTone(8);
// startTime = -1;
// }
}
E. CONCLUSIONS
Generally, our project has satisfied our goal. Our expectation of the project is varying with the process of making crafts and coding going on. At last, our goal is to let two people interact with the Project and bring the two people together to interact with each other as well. In the presentation, our audience, however, turned out to treat the game as a competitive one so they were trying to compete with each other to see who found the note which can light the 3 LEDs first. Maybe we could set the codes on only one Arduino to make sure the two players can interact with each other more. Besides, the volume of the buzzers was still low. If we had more time, we would try to either add more buzzers or use something else instead of buzzers. Honestly, I learned more about codes when I was doing the project than when I was in class. The difficult part is that we not only have to set the codes correctly, but we also have to test if the codes can help achieve our goal, for example, letting the LED on when the player is playing a certain note. Moreover, I learned a lot from the process of making the project. We met so many challenges and adjusted our plan several times to make our project practical and interesting.
Leave a Reply