Sensor Display – Cheap Dance Dance

Guaranteed to make your party the hottest of the year for less than $20. Regular DD games cost hundreds of dollars, and play insufferable pop music. Cheap Dance Dance can be set to any of your own music, although lounge is recommended.

CDD works by detecting if the player’s limb is in the right spot by the absence or the presence of light in the area where the limbs shadow is supposed to fall on the wall with simple photoresistors. Thats why the projection serves both as the command screen and the data the the sensors will take in. Although I would have liked to work out some of the details of CDD, like adding graphics (stick figure) as instructions instead of text instructions, or including music built in the program, it works fairly well. The only big flaw is that the connections I made from the wires to the photoresistors are finicky, and they can be a bit slow, also sometimes the game awards non-deserved points every once in a while.

photoresistorTImes5_bb

IMG_0260

Screen Shot 2014-11-06 at 10.37.58 AM

Screen Shot 2014-11-06 at 10.36.43 AMScreen Shot 2014-11-06 at 10.42.35 AM

 

Processing Code:


//Charlotte Stiles 2014

import processing.serial.*;
Serial myPort; 
int startTime;
int elapsTime;
boolean drawRandom = false;
boolean getPoints = false;
int happenOnce = 0;
boolean leftArm, rightArm, bothArms, rightLeg, leftLeg;
int choose = 0; 
int r, g, b,sec, points,getPointsOnce;
boolean rUp, gUp, bUp;
float rUpf, gUpf, bUpf, rDownf, gDownf, bDownf;
PFont font; 

int valueA; // Sensor Value A
int valueB; // Sensor Value B
int valueC;
int valueD;
int valueE;
 
//------------------------------------
void setup() {
 background(100);
 size(400, 400); 
 font = loadFont("Silom-48.vlw");
 textFont(font,32);
 startTime=0;
 sec=3;
 points = 0;
 getPointsOnce = 0;

 r=100;
 g=100;
 b=100;
 // List my available serial ports
 int nPorts = Serial.list().length; 
 for (int i=0; i < nPorts; i++) {
 println("Port " + i + ": " + Serial.list()[i]);
 } 
 
 String portName = Serial.list()[5]; 
 myPort = new Serial(this, portName, 9600);
 serialChars = new ArrayList();
}
 
//------------------------------------
void draw() {
 
 // Process the serial data. This acquires freshest values. 
 processSerial();
 

 rainbow();//changes background



 elapsTime = (millis() - startTime)/1000; //time restarts each time a new move is called


 if ( elapsTime % sec == 0 && elapsTime != 0) { //change the sec to whatever second you want to wait

 drawRandom = true;
 } else {
 drawRandom = false;
 happenOnce = 0;//sets it to 0 when draw random is false so it doesnt trigger
 }

 // println(elapsTime);

 if (drawRandom) {
 if (happenOnce == 0) {
 getPointsOnce = 0;
 // fill(255, 0, 0);
 choose = int(random(1, 5));
 rndColors(); // sets random colors 
 startTime = millis();//resets the time 
 happenOnce = happenOnce + 1;//so it only happens for one frame
 getPointsOnce = 0;
 getPoints=false;
 }
 }
 
 if(getPoints){
 if(getPointsOnce == 0){
 points = points + (sec-elapsTime);//the quicker you are the more points you get
 getPointsOnce = getPointsOnce+1;//so you can only get points once per move
 } 
 }
 text(points,width/2,height*.75);
 switch(choose){
 case 1://///////////////////////////left arm
 text("LEFT ARM up", width/2, 100);
 if (leftArm) {
 getPoints=true;
 text("GOOOD JOB", width/2, 200);
 } else {
 getPoints=false;
 }
 break;
 
 case 2:////////////////////////both arms 
 text("both ARMs up", width/2, 100);
 if (bothArms) {
 getPoints = true;
 text("GOOOD JOB", width/2, 200);
 } else {
 getPoints = false;

 }
 break;
 
 case 3:////////////////////////////////right arm 
 text("right ARM", width/2, 100);
 if (rightArm) {
 getPoints = true;
 text("GOOOD JOB", width/2, 200);
 } else {
 getPoints = false;
 }
 break;
 
 case 4://///////////////////////left leg
 text("LEFT leg outt", width/2, 100);
 if (leftLeg) {
 getPoints=true;
 text("GOOOD JOB", width/2, 200);
 } else {
 getPoints = false;
 }
 break;
 case 5:////////////////////////right leg
 text("rightLeg outt", width/2, 100);
 if (rightLeg) { 
 getPoints = true;
 text("GOOOD JOB", width/2, 200);
 } else {
 getPoints = false;
 }
 break;
 default:
 textAlign(CENTER);
 int startTime = -elapsTime +sec;
 text("starts in: "+ startTime , width/2,40);
 break;
 }



 //sets which photoresistor to true if it has a shadow over it
 if (valueA>200) leftArm = true;
 else {
 leftArm = false;
 }
 if (valueB>200) bothArms=true;
 else {
 bothArms = false;
 }
 if (valueC>200) rightArm=true;
 else {
 rightArm = false;
 }
 if (valueD>200)leftLeg = true;
 else {
 leftLeg = false;
 }
 if (valueE>200) rightLeg = true;
 else {
 rightLeg = false;
 }
 println(getPointsOnce);
}

 
ArrayList serialChars; // Temporary storage for received serial data
int whichValueToAccum = 0; // Which piece of data am I currently collecting? 
boolean bJustBuilt = false; // Did I just finish collecting a datum?
 
void processSerial() {
 
 while (myPort.available () > 0) {
 char aChar = (char) myPort.read();
 
 // You'll need to add a block like one of these 
 // if you want to add a 3rd sensor:
 if (aChar == 'A') {
 bJustBuilt = false;
 whichValueToAccum = 0;
 } else if (aChar == 'B') {
 bJustBuilt = false;
 whichValueToAccum = 1;
 }else if (aChar == 'C') {
 bJustBuilt = false;
 whichValueToAccum = 2;
 } else if (aChar == 'D') {
 bJustBuilt = false;
 whichValueToAccum = 3;
 }else if (aChar == 'E') {
 bJustBuilt = false;
 whichValueToAccum = 4;
 }
 else if (((aChar == 13) || (aChar == 10)) && (!bJustBuilt)) {
 // If we just received a return or newline character, build the number: 
 int accum = 0; 
 int nChars = serialChars.size(); 
 for (int i=0; i < nChars; i++) { 
 int n = (nChars - i) - 1; 
 int aDigit = ((Integer)(serialChars.get(i))).intValue(); 
 accum += aDigit * (int)(pow(10, n));
 }
 
 // Set the global variable to the number we captured.
 // You'll need to add another block like one of these 
 // if you want to add a 3rd sensor:
 if (whichValueToAccum == 0) {
 valueA = accum;
 // println ("A = " + valueA);
 } else if (whichValueToAccum == 1) {
 valueB = accum;
 // println ("B = " + valueB);
 }else if (whichValueToAccum == 2) {
 valueC = accum;
 }else if (whichValueToAccum == 3) {
 valueD = accum;
 }else if (whichValueToAccum == 4) {
 valueE = accum;
 }
 
 // Now clear the accumulator
 serialChars.clear();
 bJustBuilt = true;
 
 } else if ((aChar >= 48) && (aChar <= 57)) {
 // If the char is between '0' and '9', save it.
 int aDigit = (int)(aChar - '0'); 
 serialChars.add(aDigit);
 }
 }
}



 void rndColors(){
 rUp = true; gUp = true; bUp = true;
 //Randoms for Rainbow mode...
 rUpf = random(1, 2);//randomly choose incrememnts
 gUpf = random(1, 2);
 bUpf = random(1, 2);
 rDownf = random(1, 2);
 gDownf = random(1, 2);
 bDownf = random(1, 2);
 r = int(random(100,255));
 g=int(random(100,255));
 b=int(random(100,255));
 }


void rainbow() {
 background(r,g,b);
 
 //////this part of the code is based off of the rainbow part of https://openprocessing.orgsketch/7298 by Thaipo
 
 if (rUp) {
 r += rUpf;
 } else {
 r -= rDownf;
 }
 if (gUp) {
 g += gUpf;
 } else {
 g -= gDownf;
 }
 if (bUp) {
 b += bUpf;
 } else {
 b -= bDownf;
 }
 ///////////////////decide if color is going up or down
 if (r > 255) {
 rUp = false;
 } 
 if (r < 100) {
 rUp = true;
 }
 if (g > 255) {
 gUp = false;
 } 
 if (g < 100) {
 gUp = true;
 }
 if (b > 255) {
 bUp = false;
 } 
 if (b < 100) {
 bUp = true;
 }
 }

Arduino Code:
 

// This Arduino program reads two analog signals, 
// such as from two potentiometers, and transmits 
// the digitized values over serial communication. 
 
int sensorValue0 = 0;  // variable to store the value coming from the sensor
int sensorValue1 = 0;  // variable to store the value coming from the other sensor
int sensorValue2 = 0;
int sensorValue3 = 0;
int sensorValue4 = 0;

void setup() {
  Serial.begin(9600);  // if in the serial monitor it doesnt have this number, use dropdown menue to change that   
}
 
void loop() {
 
  // Read the value from the sensor(s):
  sensorValue0 = analogRead (A0);  // reads value from Analog input 0
  sensorValue1 = analogRead (A1);  // reads value from Analog input 1    
  sensorValue2 = analogRead (A2);
  sensorValue3 = analogRead (A3);
  sensorValue4 = analogRead (A4);
  
  Serial.print ("A"); 
  Serial.println (sensorValue0); 
  Serial.print ("B"); 
  Serial.println (sensorValue1);  
  Serial.print ("C"); 
  Serial.println (sensorValue2);  
  Serial.print ("D"); 
  Serial.println (sensorValue3); 
  Serial.print ("E"); 
  Serial.println (sensorValue4); 
 
  delay (50);   // wait a fraction of a second, to be polite
}
 

Comments are closed.