Dance Dance Devaluation
Our musical instrument is a game called Dance Dance Devaluation. The idea is that you can augment the music by dancing along the music. It has pre-recorded compositions of different tempo which you can select using a Potentiometer. As you dance on the 3 tiles it produces different percussion sounds. You can also shut down the music and create music by just dancing. Also as you dance, the waveform on the screen follows the music.
A demo is here http://www.youtube.com/watch?v=a3yNYhFiiJQ
Components Used:
1. 3 FSRs
2. 1 Potentiometer
3. Arduino
4. Ceramic Tiles
5. Rubber tiles
6. Wires etc.
Processing code:
import ddf.minim.*; import processing.serial.*; int STOPPED = 1; int TEMPO1 = 2; int TEMPO2 = 3; int TEMPO3 = 4; int currentTempo = STOPPED; int lineFeed = 10; Serial port; String buf=""; int count = 0; AudioPlayer playerBackground; AudioPlayer player1; AudioPlayer player2; AudioPlayer player3; Minim minim; int TRIGGER = 50; int[] pressureValues = new int[4]; int[] oldPressureValues = new int[4]; void setup() { size(512, 200, P2D); minim = new Minim(this); // load a file, give the AudioPlayer buffers that are 2048 samples long playerBackground = minim.loadFile("Background0.wav", 2048); player1= minim.loadFile("1.wav",2048); player2= minim.loadFile("2.wav",2048); player3 = minim.loadFile("3.wav",2048); port = new Serial(this, Serial.list()[0], 9600); port.bufferUntil(lineFeed); } void draw() { background(0); stroke(255); // draw the waveforms // the values returned by left.get() and right.get() will be between -1 and 1, // so we need to scale them up to see the waveform // note that if the file is MONO, left.get() and right.get() will //return the same value for(int i = 0; i < playerBackground.left.size()-1; i++) { line(i, 50 + playerBackground.left.get(i)*50, i+1, 50 + playerBackground.left.get(i+1)*50); line(i, 150 + playerBackground.right.get(i)*50, i+1, 150 + playerBackground.right.get(i+1)*50); } } void serialEvent(Serial p) { //println("Serial Event"); buf= port.readString(); println("Read:"+buf); if(buf != "") { pressureValues = parse(buf); playMusic(); for (int i = 0; i < pressureValues.length; i++) oldPressureValues[i] = pressureValues[i]; //println(pressureValues); } } void playMusic(){ playOrStop(); println("OldPressureValues:"+oldPressureValues[0]+";"+oldPressureValues[1]+";"+oldPressureValues[2]+";"+oldPressureValues[3]); println("NewPressureValues:"+pressureValues[0]+";"+pressureValues[1]+";"+pressureValues[2]+";"+pressureValues[3]); if (oldPressureValues[1] >=10 && pressureValues[1] > 25) { player1= minim.loadFile("1.wav",2048); player1.play(); } if (oldPressureValues[2] >=10 && pressureValues[2] > 25) { player2= minim.loadFile("2.wav",2048); player2.play(); } if (oldPressureValues[3] >=10 && pressureValues[3] > 25) { player3= minim.loadFile("3.wav",2048); player3.play(); } } void playOrStop(){ int diff = (oldPressureValues[0]/256) - (pressureValues[0]/256); int value = pressureValues[0]/256; if(diff != 0) { playerBackground.pause(); if(value != 0) { String fileName = "Background" + value + ".wav"; playerBackground = minim.loadFile(fileName,2048); playerBackground.play(); } } } void stop() { // always close Minim audio classes when you are done with them playerBackground.close(); player1.close(); player2.close(); player3.close(); //player4.close(); minim.stop(); super.stop(); } int[] parse(String string) { try{ println(string); int[] intValues = new int[4]; String[] strValues = new String[4]; strValues = string.split(","); println(strValues); for(int i=0;ilength ;i++) { intValues[i] = Integer.parseInt(strValues[i].trim()); } return intValues; }catch(Exception e){ int[] x = {0,0,0,0}; return x; } } Arduino Code:
int sensorPin1 = 0; // select the input pin for the sensor int sensorPin2 = 1; // select the input pin for the sensor int sensorPin3 = 2; // select the input pin for the sensor int sensorPin4 = 3; // select the input pin for the sensor int val1 = 0; // variable to store the value coming from the sensor int val2 = 0; // variable to store the value coming from the sensor int val3 = 0; // variable to store the value coming from the sensor int val4 = 0; // variable to store the value coming from the sensor void setup() { Serial.begin(9600); } void loop() { val1 = analogRead(sensorPin1); // read the value from the sensor, 0-1023 val2 = analogRead(sensorPin2); // read the value from the sensor, 0-1023 val3 = analogRead(sensorPin3); // read the value from the sensor, 0-1023 val4 = analogRead(sensorPin4); // read the value from the sensor, 0-1023 Serial.println(toString4(val1, val2, val3, val4)); // writing the value to the PC via serial connection delay(50); // rest a little... } String toString4(int val1, int val2, int val3, int val4) { String s1 = String(val1); String s2 = String(val2); String s3 = String(val3); String s4 = String(val4); String retVal = String(); retVal = s1 + "," + s2 + "," + s3 + "," + s4; return retVal;
(1 vote)