Announcements

November 24, 2007
Reading for November 27th, are now posted. Enjoy!

October 2, 2007
To upload your thoughtless acts, create a new assignment page like any other lab. You'll see "Thoughtless Acts" listed as one of the assignment options.

May 24, 2008
This site has been archived and is no longer editable. Stay tuned for the next version, coming in the fall!


Musical Mimic Game

Project Members: 
Anirban Sen
Farley Gwazda
Jill Blue Lin
Kenghao Chang

Concept:

Our musical instrument is designed to be a learning and mimicking game designed for 2 players. Each player will control a set of 4 levers (we used potentiometers). Each lever will play a different instrument. We will have a tonal instrument in the form of a piezo speaker, a percussion instrument in the form of a propellor and a stainless steel drum, a second percussion instrument in the form of a vibrating skewer instrument, and lastly electronic output from a computer. We are having the players take turns at controlling their levers at the flip of a switch. The switch will turn off one set of controls and turn on the other set. There will also be 2 LEDs to indicate which player's turn it is to play the music. The object of the game is for one player to mimic the other player's tone, pitch, and sequence after hearing it played by the first player.

 

Components:

4 arduino processors

8 potentiometers

1 piezo speaker

1 DC motor (propellor percussion instrument)

1 stainless steel drum 

1 servo motor

2 LEDs

 

Code for piezo speaker tonal instrument:

int potPin = 0; // select the input pin for the potentiometer

int potPin2 = 1; // select the input pin for the second potentiometer

int speakerPin = 8;

int buttonPin = 7;

 

int val = 0;

 

void setup() {

pinMode(speakerPin, OUTPUT);

beginSerial(9600);

Serial.println("ready");

}

 

void loop() {

int player = digitalRead(buttonPin);

digitalWrite(speakerPin, LOW);

 

if (player == 0){

val = analogRead(potPin); // read value from the sensor

val = val*2; // process the value a little

}else{

val = analogRead(potPin2);

}

 

for( int i=0; i<500; i++ ) { // play it for 50 cycles

digitalWrite(speakerPin, HIGH);

delayMicroseconds(val);

digitalWrite(speakerPin, LOW);

delayMicroseconds(val);

}

}

 

Code for DC motor percussion:

/*
 * two pots fades one motor, which pot controlled by switch
 * modified version of AnalogInput
 */
 
int buttonPin = 7;

int potPin = 0;   // select the input pin for the potentiometer
int potPin2 = 1;  // select another input pin for the potentiometer
int motorPin = 9; // select the pin for the Motor
int val = 0;      // variable to store the value coming from the sensor
void setup() {
  Serial.begin(9600);
}
void loop() {
 
  int player = digitalRead(buttonPin);
  Serial.println(player);
   if (player == 0) {
   val = analogRead(potPin) ;
 } else {
   val = analogRead(potPin2);
 }

  analogWrite(motorPin, val/4); // analogWrite can be between 0-255
}
 

Code for Playing Sound File from Processing:

[processing part]

import processing.serial.*;
import ddf.minim.*;
import ddf.minim.signals.*;

AudioSnippet snippet;
//String portname = "/dev/tty.usbserial-A4001lQY"; // or "COM5"
String portname = "COM4";
Serial port;
void setup()
{
size(100, 100);
frameRate(10);
smooth();

  port = new Serial(this, portname, 9600);
Minim.start(this);

snippet = Minim.loadSnippet("bikebell.aiff");

}

void draw()
{
}

void keyPressed()
{
if ( key == 'p' )
{
snippet.play();
snippet.rewind();
println("read");
}
}

void serialEvent(Serial p) {
  int c = port.read();
  if (c == 'p') {
  snippet.play();
  snippet.rewind();
  println("read");
}
}

void stop()
{
snippet.close();
}

[Arduino part]


/*
 * one pot fades one led
 * modified version of AnalogInput
 * by DojoDave <http://www.0j0.org>
 * http://www.arduino.cc/en/Tutorial/AnalogInput
 */
int potPin = 0;   // select the input pin for the potentiometer
int potPin2 = 1;   // select the input pin for the potentiometer
int val = 0;      // variable to store the value coming from the sensor

int buttonPin = 7;
int buttonVal, lastButtonVal;
int player = 0;
int lastVal = 0;
int player0Pin = 9;
int player1Pin = 10;

void setup() {
   pinMode(player0Pin,   OUTPUT);
   pinMode(player1Pin,   OUTPUT);
   pinMode(8,   OUTPUT);
 
   analogWrite(player0Pin, 255);
   analogWrite(player1Pin, 0);
  
   Serial.begin(9600);
}
int played = 0;
void loop() {
  buttonVal = digitalRead(buttonPin);
  if (buttonVal != lastButtonVal && buttonVal == 1) {
    player = 1-player;
    analogWrite(player0Pin, 255 * (1- player));
    analogWrite(player1Pin, 255 * player);
    digitalWrite(8, player);
    Serial.println(player);
    played = 0;
  }
 
  lastButtonVal = buttonVal;
 
  if (player == 0) {
    val = analogRead(potPin) / 4;    // read the value from the sensor, between 0 - 1024
  } else {
    val = analogRead(potPin2) / 4;
  }
 
  if (val == 0 && played == 0) {
    Serial.println('p');
    played = 1;
  }
  else if (val != 0)
  {
    played = 0;
  }
  delay(40);
}


AttachmentSize
final appearance.JPG696.34 KB
percussion instrument.JPG655.87 KB
skewer instrument.JPG659.34 KB

Powered by Drupal - Design by Artinet