Category: Assignment-10-SensorDisplay

please don’t touch me : sensor display

I enjoy the idea that a computer can have the capacity to feel and relay back those feelings, so I wanted to create a simple default, visual state for the computer. The default state is represented by a loop of three ellipses (like an ellipsis), and when this state is interrupted by the touch of a person the program responds with a very human-like response.

 

Screen Shot 2014-11-12 at 16.05.58

DSC05539

Screen Shot 2014-11-12 at 15.24.07

 

 

Processing Code:

import processing.serial.*;
Serial myPort;


int valueA;  // Sensor Value A
int valueB;  // Sensor Value B

int count = 2;

//------------------------------------
void setup() {
size(600, 200);


smooth ();
// 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()[2];
myPort = new Serial(this, portName, 9600);
serialChars = new ArrayList();
}
//------------------------------------

//------------------------------------
void draw() {

// Process the serial data. This acquires freshest values.
processSerial();

background (130);

// moment sensor is touched, text shows
if (valueA > 5) {

textSize (25);
fill (180);
text ("please stop, i don't feel like being touched", 50,45);

// this sets up ellipses to loop
}
else{
if(count<50){
noStroke ();
fill(240);
ellipse(250,100,20,20);
count++;
}
else if(count<100){
fill(240);
ellipse(250,100,20,20);
ellipse(300,100,20,20);
count++;
}
else if(count<150){
fill(240);
ellipse(250,100,20,20);
ellipse(300,100,20,20);
ellipse(350,100,20,20);
count++;
}
else if (count<175){
fill(130);
noStroke();
ellipse(250,100,20,20);
ellipse(300,100,20,20);
ellipse(350,100,20,20);
count++;
}
else{
count=2;
}
}
}


//---------------------------------------------------------------


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 == 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);
}

// 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);
}
}
}

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

void setup() {
Serial.begin(9600);  // initialize serial communications
}

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

Serial.print ("A");
Serial.println (sensorValue0);
Serial.print ("B");
Serial.println (sensorValue1);

delay (50);   // wait a fraction of a second, to be polite
}

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 http://www.openprocessing.org/sketch/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
}
 

Helicopter Game (Sensor Display)

For my sensor display I wanted to make use of the proximity sensor. I chose to create a portrayal of an old flash game I remembered playing. I’m not sure what the origin of it is, but a portrayal of it can be found at http://www.helicopter-game.org/ . However, for my version the helicopter is controlled by the height of the player’s hand over the sensor device. The device is meant to look like a black box which is typically associated with aviation. I made sure to use similar colors for the game and the box.

Here is a video of the project running:

Here are some images:
helicopter_boxhelicopter_processing_display

Here is the fritzing diagram:
helicopter

Here is the Processing code:

// Helicopter Game
// If available this game will play using input from an arduino based accessory.
// Author: Matthew Kellogg
// Date: October 29, 2014
//Copyright 2014 Matthew Kellogg
// 
 
// Import the Serial library and create a Serial port handler
import processing.serial.*;
import ddf.minim.*;
Serial myPort;   

ArrayList ceilHeight = new ArrayList();
ArrayList floorHeight = new ArrayList();

float heliX = 200.0;
float heliY = 100.0;

color neonGreen = color(20, 200, 40);
int strokeW = 10;

int finalScore = 0;
boolean wrecked = false;

AudioPlayer player;
AudioPlayer explode;
Minim minim; //context
// Hey you! Use these variables to do something interesting. 
// If you captured them with analog sensors on the arduino, 
// They're probably in the range from 0 ... 1023:
int valueA;  // Sensor Value A
int valueB;  // Sensor Value B
 
//------------------------------------
void setup() {
  
  size(1280,800);
  
  // List my available serial ports
  int nPorts = Serial.list().length; 
  for (int i=0; i < nPorts; i++) {     println("Port " + i + ": " + Serial.list()[i]);   }      // Choose which serial port to fetch data from.    // IMPORTANT: This depends on your computer!!!   // Read the list of ports printed by the code above,   // and try choosing the one like /dev/cu.usbmodem1411   // On my laptop, I'm using port #4, but yours may differ.   if (Serial.list().length > 0){
  String portName = Serial.list()[0]; 
  myPort = new Serial(this, portName, 9600);
  serialChars = new ArrayList();
  }
  
  resetBounds();
  
  //audio
  minim = new Minim(this);
  player = minim.loadFile("helicopter-hovering-01.mp3", 2048);
  explode = minim.loadFile("explosion.mp3", 2048);
  player.loop();
}

void stop(){
  player.close();
  explode.close();
  minim.stop();
  super.stop();
}

void resetBounds(){
  ceilHeight.clear();
  floorHeight.clear();
  // ceiling and floor
  for (int i = 0; i -2 <= width/200; i++){
    ceilHeight.add(10);
    floorHeight.add(height - 10);
  }
}

void keyPressed(){
  if ((key == 'R' || key == 'r') && wrecked){
    wrecked = false;
    frameCount = 0;
    finalScore = 0;
    resetBounds();
    player.loop();
    explode.pause();
    explode.rewind();
  }
}

//------------------------------------
void draw() {
  background (10,20,60);
  
  if (wrecked){
    if ((frameCount/5)%2 == 0){
      fill(neonGreen);
      drawHelicopter(200, (int) heliY, false);
    }else{
      fill(255,0,0);
    }
    
    textAlign(CENTER);
    textSize(60);
    text("FINAL SCORE: " + finalScore,width/2, height/2-70);
    text("Press 'R' to restart", width/2, height/2 + 10);
  }else{
    // Process the serial data. This acquires freshest values. 
    if (myPort != null){
      processSerial();
      heliY = 0.9*heliY + 0.1*(map(valueA, 0, 100, height - 14*4, 100));
    }
    else{
      heliY = mouseY;
    }
    
    //Check bounds
    int checkIndex = (0 + 2*(frameCount%100))/100;
    int ceilBound = max((Integer)ceilHeight.get(checkIndex), (Integer)ceilHeight.get(checkIndex +1));
    int floorBound = min((Integer)floorHeight.get(checkIndex), (Integer)floorHeight.get(checkIndex + 1));
    if ((heliY - 100 < ceilBound) ||        (heliY + 60 > floorBound)){
      wrecked = true;
      finalScore = frameCount/5;
      player.pause();
      player.rewind();
      explode.play();
    }
    
    if (frameCount%100 == 0){
      ceilHeight.remove(0);
      floorHeight.remove(0);
      int pCeil = (Integer)ceilHeight.get(ceilHeight.size()-1);
      int pFloor = (Integer)floorHeight.get(floorHeight.size()-1);
      ceilHeight.add((int)random(max(10,pCeil-100), min(pCeil+100, pFloor -350)));
      floorHeight.add((int)random(max(pCeil +350, pFloor -100), min(height, pFloor + 100)));
    }
    
    drawBounds();
    drawHelicopter(200, (int)heliY,false);
      
    //score
    textAlign(RIGHT);
    textSize(30);
    String score = "Score: "+frameCount/5;
    int scoreW = (int)(textWidth(score));
    
    fill(0);
    strokeWeight(strokeW);
    stroke(neonGreen);
    rect(width - scoreW -20, -10, scoreW+30, 80);
    
    fill(neonGreen);
    noStroke();
    text(score, width - 10, 50);
  }
  
}

//draws the ceiling and floor
void drawBounds(){
  fill(0);
  strokeWeight(strokeW);
  stroke(neonGreen);
  beginShape();
  vertex(width+10, -20);
  vertex(-20,-20);
  println("Ceil size is " + ceilHeight.size());
  for (int i = 0; i< ceilHeight.size(); i++){
    vertex(200*i - 2*(frameCount%100), (Integer)ceilHeight.get(i));
  }
  endShape(CLOSE);
  
  beginShape();
  vertex(width+20, height+20);
  vertex(-20, height+20);
  for (int i = 0; i< floorHeight.size(); i++){     vertex(200*i - 2*(frameCount%100), (Integer)floorHeight.get(i));   }   endShape(CLOSE);   strokeWeight(1); } //bounds of the helicopter are -45,-25 to 30, 14 void drawHelicopter(int x, int y, boolean bounds){   pushMatrix();   fill(neonGreen);   noStroke();   translate(x,y);   scale(4, 4);   ellipse(0,-20, 60, 10);   ellipse(0, 0, 25, 16);   rect(-30, -4, 30, 6);   ellipse(-30,0, 15, 15);   if (bounds){     noFill();     rectMode(CORNERS);     rect(-45, -25, 30,14);     rectMode(CORNER);   }   strokeWeight(2);   stroke(neonGreen);   line(-8, 14, 8, 14);   line(8, 14, 12, 10);   popMatrix(); }   //--------------------------------------------------------------- // The processSerial() function acquires serial data byte-by-byte,  // as it is received, and when it is properly captured, modifies // the appropriate global variable.  // You won't have to change anything unless you want to add additional sensors.    /* The (expected) received serial data should look something like this:    A903  B412  A900  B409  A898  B406  A895  B404  A893  B404  ...etcetera.  */   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 == 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);       }         // 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);
    }
  }
}

Here is the Arduino code:

/* 
 * Helicopter controller
 * Author: Matthew Kellogg
 * Date: October 22, 2014
 */
int ledPin = 5;    // LED connected to digital pin 9

void setup()  { 
  pinMode(ledPin, OUTPUT);
  Serial.begin(9600);
} 

static const int lowThresh = 200;
static const int hiThresh = 612;

void loop()  {
  int val = analogRead(0);
  if (val > lowThresh && val < hiThresh){
    analogWrite(ledPin, map(val, lowThresh, hiThresh, 0, 255));
    //tone(11, map(val, lowThresh, hiThresh, 60, 4400));
    Serial.print("A" + String((int)map(val, lowThresh, hiThresh, 100, 0)) + "\n");
  } else { 
    analogWrite(ledPin, 0);
    //noTone(11);
  }
}

SensorDisplay: Public Donation Machine

The Public Donation Machine is a small device that is meant to be placed in a high-traffic public space. The machine controls how a large donation of money will be divided between two organizations.

The device lets the public vote on which organization will receive the most money. As people pass by The Public Donation Machine, they can move the slider to exactly the place that represents how much they support each organization. After thousands of people give their input, the money donated will represent an average amount for each cause that fairly represents the will of the population.

IMG_2011

In theory this seems like it would work. But what would actually happen is, given a controversial enough issue (eg. pro life vs. pro-choice organization) and a large enough sum on money (one million dollars?), it would devolve from a fair voting system into a massive battle of fighting over the control of the device and long stretches of time guarding and defending the ‘territory’ of the surrounding area.

// 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
 
void setup() {
  Serial.begin(9600);  // initialize serial communications    
}
 
void loop() {
 
  // Read the value from the sensor(s):
  sensorValue0 = analogRead (A0);  // reads value from Analog input 0 
 
  Serial.print ("A"); 
  Serial.println (sensorValue0);  
 
  delay (50);   // wait a fraction of a second, to be polite
}

Sensors: Thunder

Thunder

I was working on a site fairly recently where a nearby building was using an old siren as a warning. The kind that served as warnings for the Blitzkrieg. This got me thinking about warnings, and I ended up wanting to work with that same sound. Thunder is, in concept, a simulator for someone reminiscing about the blitz. It consists of three sensors: one proximity sensor on the headphones, and 2 light sensors on the board. Triggereing all of them will cause a recording of  blitz sirens to play. Removing your hands or taking off the headphones causes the audio to stop.

//video here

In this video, the headphones are unplugged for demonstration reasons. Originally I wanted to have it so that the user’s hands would have to cover their ears, but this led to complications. The act of physically placing your hands in a certain place functions as giving an entry and exit to the space of memory.

IMG_1074

the full rig

IMG_1081

the two green squares are light sensors, and the purple/white cable set leads to  the headphone sensor. the other leads nowhere and does nothing.

IMG_1082

Arduino Code. Modified to return a yes/no response

int sv0 = 0;  // variable to store the value coming from the sensors
int sv1 = 0;
int sv2 = 0; 
int req = 400;
 
void setup() {
  Serial.begin(9600);  // initialize serial communications    
}
 
void loop() {
 
  // Read the value from the sensors:
  sv0 = analogRead (A0); 
  sv1 = analogRead (A1);  
  sv2 = analogRead (A2);  
 
  //Serial.print(sv0);
  //Serial.print(" : ");
  //Serial.print(sv1);
  //Serial.print(" : ");
  //Serial.println(sv2);
  if((sv0 < req) && (sv1 < req) && (sv2 < req)){
    Serial.println ("A");
  } else {
    Serial.println ("B");
  }
  delay (50);   // wait a fraction of a second, to be polite
}

Processing Code

// Processing program to handle audio playing
 
// Import the Serial library and create a Serial port handler
import processing.serial.*;
Serial myPort;   
 
import ddf.minim.*; 
Minim minim;
AudioPlayer player; 
 
int valueA;  // Sensor Value A
int valueB;  // Sensor Value B
Boolean running = false;
 
//------------------------------------
void setup() {
  size(1024, 200);
 
  // List my available serial ports
  int nPorts = Serial.list().length; 
  for (int i=0; i &lt; nPorts; i++) {
    println("Port " + i + ": " + Serial.list()[i]);
  } 
 
  // Choose which serial port to fetch data from. 
  // IMPORTANT: This depends on your computer!!!
  // Read the list of ports printed by the code above,
  // and try choosing the one like /dev/cu.usbmodem1411
  // On my laptop, I'm using port #4, but yours may differ.
  String portName = Serial.list()[5]; 
  myPort = new Serial(this, portName, 9600);
  serialChars = new ArrayList();
  
  minim = new Minim(this);
  player = minim.loadFile("AirRaidSirens1.wav");
  
}
 
//------------------------------------
void draw() {
 
  // Process the serial data. This acquires freshest values. 
  processSerial();
 
  background (150);  
 
}
 
 
//---------------------------------------------------------------
// The processSerial() function acquires serial data byte-by-byte, 
// as it is received, and when it is properly captured, modifies
// the appropriate global variable. 
// You won't have to change anything unless you want to add additional sensors. 

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 () &gt; 0) {
    char aChar = (char) myPort.read();
 
    // checks whether all sensors are currently triggered or not.
    if (aChar == 'A' &amp;&amp; running == false) {
      running = true;
      player.play();
      println("playing...");
    } else if (aChar == 'B' &amp;&amp; running == true) {
      running = false;
      println("stopping");
      player.pause();
      player.rewind();
    }
  }
}

 

OFace

For this assignment, I decided to use the squeezing sensor to work with my program. I wanted to create an image of a mouth that oped wider and wider the harder you squeezed the sensor thus resembling the sensual orgasmic face. I thought about using the twisting sensor to resemble the nipple however, that sensor was more of an on and off sensor that wouldn’t need constant human touch to activate it. I need more help with a more interactive/ gaming/ goal orient visual experience. One thought I had was to have a timer going to see if the individual to “stimulate” at a consistent temperature for a certain amount of time. However, that seems to bland as well. I do not have documentation because I have forgotten to take out my USB cord from my suitcase every single time I leave home for the day.

<

import processing.serial.*;
Serial myPort;

// Hey you! Use these variables to do something interesting.
// If you captured them with analog sensors on the arduino,
// They’re probably in the range from 0 … 1023:
int valueA; // Sensor Value A

float runningAvgA;

//————————————
void setup() {
size(400, 400);
runningAvgA = 0;

// List my available serial ports
int nPorts = Serial.list().length;
for (int i=0; i < nPorts; i++) { println("Port " + i + ": " + Serial.list()[i]); } // Choose which serial port to fetch data from. // IMPORTANT: This depends on your computer!!! // Read the list of ports printed by the code above, // and try choosing the one like /dev/cu.usbmodem1411 // On my laptop, I'm using port #4, but yours may differ. String portName = Serial.list()[4]; myPort = new Serial(this, portName, 9600); serialChars = new ArrayList(); } //------------------------------------ void draw() { // Process the serial data. This acquires freshest values. processSerial(); strokeJoin (ROUND); runningAvgA = 0.95*runningAvgA + 0.05*valueA; background (200,100,100); float m = map(runningAvgA, 0,1000, 0, height); strokeWeight(20); stroke(255, 100, 100); ellipse(width/2, height/2, 200, m); fill (0); stroke(0); strokeWeight(1); ellipse (width/2, height/2, 200, m); } //--------------------------------------------------------------- // The processSerial() function acquires serial data byte-by-byte, // as it is received, and when it is properly captured, modifies // the appropriate global variable. // You won't have to change anything unless you want to add additional sensors. /* The (expected) received serial data should look something like this: A903 B412 A900 B409 A898 B406 A895 B404 A893 B404 ...etcetera. */ 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 == 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); } // 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);
}
}
}

Arduino Code

int sensorValue0 = 0; // variable to store the value coming from the sensor

void setup() {
Serial.begin(9600); // initialize serial communications
}

void loop() {

// Read the value from the sensor(s):
sensorValue0 = analogRead (A0); // reads value from Analog input 0

Serial.print (“A”);
Serial.println (sensorValue0);

delay (50); // wait a fraction of a second, to be polite
}

Ping Sensor Carrot Karate!

Some time ago, I purchased a Parallax Ping sensor during a RadioShack sale just for the heck of it, without any idea of what to do with it.  Well, one day, this assignment came along and I decided to make use of it.  I plugged it in an Arduino Mega, and it was surprisingly easy to get working – the interesting bit was that it uses the signal pin as both input and output.  It first sends a ping out as digital output, and then the same pin switches into input to receive the pulse that bounces back.  Ok, that’s great for technology, but now what to do with it…

Hmm… aha!  The idea hit me when I was munching on some carrots.  Why not use build a carrot chopping simulator using the ping sensor to detect the position of the chop?  And that is exactly what I did.  While the project did feel somewhat rushed (I was initially intending on adding 4 different types of carrots but time got the better of me), the system works fairly well along with a very simple circuit that could be dismantled and rebuilt very fast.  I think the sound effects are a nice addition, and I will be looking forward to seeing what else I could achieve with this ultrasonic rangefinder.

Here is a concept sketch:

conceptsketch

Here is a Fritzing Diagram of the Ping Sensor (I could not find the exact model):

pingSensor

Some pics of the hardware setup:

Screen Shot 2014-10-29 at 6.25.21 PM Screen Shot 2014-10-29 at 6.25.43 PM

Some Processing Screens:

carrot_ee_title

carrot_ee_game

The Arduino Code:

/* Simple ping sensor carrot chopping game

/* --- PRE SETUP --- */
int pingPin = 31;

/* ----- SETUP ----- */
void setup() { 
  Serial.begin(57600); 
}

/* --- MAIN LOOP --- */
void loop() {
  //send a ping out
  pingOut();
  
  //get the ping back as duration in microseconds
  unsigned int duration = pingIn();
  
  //convert the duration to a distance
  unsigned int cm = microsecondsToCm(duration);
  unsigned int in = microsecondsToIn(duration);
  
  //print the data
  //Serial.print(in);
  //Serial.print("in, ");
  
  //send the data to processing
  Serial.write(in);
      
  //delay a bit
  delay(100);

}



  
/* --- Ping Functions --- */
//sends a ping out
void pingOut() {
  pinMode(pingPin, OUTPUT);
  digitalWrite(pingPin, LOW);
  delayMicroseconds(2);
  digitalWrite(pingPin, HIGH);
  delayMicroseconds(5);
  digitalWrite(pingPin, LOW);
}

//getting the time it takes for the ping to return (in microseconds)
unsigned int pingIn() {
  pinMode(pingPin, INPUT);
  return pulseIn(pingPin, HIGH);
}

//get cm from microseconds
int microsecondsToCm(int microseconds)
{ return microseconds / 29 / 2; }
//get in from microseconds
int microsecondsToIn(int microseconds)
{ return microseconds / 74 / 2; }

The Processing Code:

/* Simple ping sensor carrot chopping game
 * by John Choi. */
 
/* --- PRE SETUP --- */
//screen width and height
int w = 800;
int h = 600;

//pre setup serial:
import processing.serial.*;
Serial serial;
boolean useSerial = true;

//pre setup minim:
import ddf.minim.*;
Minim minim;
AudioPlayer gong;
AudioPlayer chop;

//pre setup game:
PImage wood;
PImage title;
PImage[] carrot = new PImage[10];
int[] chops = {0,0,0,0,0,0,0,0,0,0};
int carrotSize = w/12;
int carrotPos = w+100;

//game vars
boolean started = false;
boolean chopStarted = false;
int chopEndTime = 5000;
int chopStartTime = 0;
int chopTime = 0;
float fade = 255;
int oldIn = 42;
int in = 42;
int time = 0;
int score = 0;

/* ----- SETUP ----- */
void setup() {
  //prepare the screen
  size(w,h);

  //setup serial
  if(useSerial == true) {
    println(Serial.list());
    serial = new Serial(this, Serial.list()[5], 57600);  
  }

  //setup minim
  minim = new Minim(this);
  gong = minim.loadFile("gong.wav");
  chop = minim.loadFile("chop.wav");
  
  //load all the images
  wood = loadImage("wood.png");
  //wood.resize(w,h);
  title = loadImage("title.png");
  title.resize(0,h);
  for(int i = 0; i < 10; i++) {     carrot[i] = loadImage("c1_"+i+".png");     carrot[i].resize(carrotSize,0);   }    } /* --- MAIN LOOP --- */ void draw() {    //update the time.   time = millis();      //refresh the screen:   background(0);   /* --- GET INPUT: --- */   //get serial input:   if(useSerial == true && serial.available() > 0) {
    in = serial.read()/2-2;
  }
  
  //key press override:
  if(keyPressed == true) {
    switch(key) {
      case '0': in = 0; break;
      case '1': in = 1; break;
      case '2': in = 2; break;
      case '3': in = 3; break;
      case '4': in = 4; break;
      case '5': in = 5; break;
      case '6': in = 6; break;
      case '7': in = 7; break;
      case '8': in = 8; break;
      case '9': in = 9; break;
    }
  }

  /* --- GAME DISPLAY --- */
  //if the game started:
  if(started == true) {
    
    //draw the wood:
    tint(255,255);
    image(wood,0,0);  
   
    //move the carrot into position:
    if(carrotPos > 0) {
      carrotPos -= 4;
    } else if (carrotPos == 0) {
      if(chopStarted == false) { 
        chopStarted = true; 
        chopStartTime = time;
      }
    }
    //update the chop time:
    chopTime = time - chopStartTime;
    //move the carrot out when time runs out:
    if(chopTime > chopEndTime && chopStarted == true) {
      if(carrotPos > -w) {
        carrotPos -= 4;
      } else {
        chopStarted = false;
        carrotPos = w+100;
        for(int i = 0; i < 10; i++) { chops[i] = 0; }
      }
    }
   
    //chop the carrot based on input:
    if(in != oldIn && chopStarted == true) {
      if(0 <= in && in < 10) {
        //if the spot was not already chopped:
        if(chops[in] == 0) {
          chops[in] = parseInt(random(15))+5;
          chop.rewind();
          chop.play();
          score += 1;
        }
      }
    }
   
    //draw the carrot:
    for(int i = 0; i < 10; i++) {
      //get the offset up to the top spot:
      int offset = carrotPos;
      for(int c = 0; c < i; c++) { offset+=chops[c]; }       //draw the carrot piece with the offset.       image(carrot[i],carrotSize*(i)+offset,h/2-carrotSize/2);     }          //draw the score:     fill(255,255);     textSize(32);     text("Chops: "+score,60,60);   }      /* --- TITLE SCREEN --- */      //if we haven't started yet:   if (started == false) {     //if input found, then start:     if(in != oldIn && time > 5000) { 
      started = true; 
      gong.play();
    }
  }
  //we have started, so fade the title out.
  else { 
    if(fade > 0) { fade -= 1.2; } 
    else { fade = 0; } 
  }
  drawTitle(); 
    
  //update oldIn:
  oldIn = in;
  
  //draw info about oldIn and in
  fill(255,255);
  textSize(32);
  text(in,700,60);
  
}

//this function draws the title screen and slowly fades it out:
void drawTitle() {
  //draw the black title background:
  fill(0,fade);
  rect(0,0,w,h);
  //draw the title:
  tint(255,constrain(fade*2.5,0,255));
  image(title,0,0); //title text
  //draw the chop to begin flickering text:  
  fill(255, (fade/255.0) * (sin(time*0.002)*255 +128));
  textSize(24);
  text("Chop to begin",w/2-90,h*9/10);
}

And if you read all that, go ahead and take a look at this stupid picture of me holding a carrot and pretending to be a chef (by Golan’s request):  Enjoy!

arduinochef

Assignment 10_Sensor Display: RandomPointillism

800px-A_Sunday_on_La_Grande_Jatte,_Georges_Seurat,_1884

Pointillism is a way of painting where every dot that is painted is calculated through scientific rules that Seurat had created. It uses pure colour and is carefully placed. Since I wanted to go against this scientific method I created a machine where people can play with the pointillism. Not 100 percent can be controlled by the interacting person but some parts can be.

20141029_155739

In my project, the person first uses the button to capture the screen. Then the screen is turned into a canvas where it starts placing dots according to the original photo colours. However, when the person pushes the button down, randomness is added to the dots. The colours and sizes and density is changed to random scale which was my way of interacting with the painting that processing was making.

IMG_20141029_154855

Sensor_Display

 

 

Code for the Arduino

int buttonState = 0;         // variable for reading the pushbutton status

void setup() {       
 Serial.begin(9600); 
}

void loop(){
  // read the state of the pushbutton value:
  buttonState = digitalRead(13);
  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  Serial.println(buttonState);
  delay(100);
}

Code for the Processing

import processing.video.*; 
import processing.serial.*;

Serial myPort;
char val;
float sizeR;
float randomC; 
float lightness;

PImage img;

Capture myCapture; 

String filename = "portrait.jpg"; 

void setup () { 
  size (640, 480); 
  myCapture = new Capture(this, width, height, 30); 
  myCapture.start();
  
  String portName = Serial.list()[2]; 
  myPort = new Serial(this, portName, 9600);
  
  background(255);
  smooth();
} 

void captureEvent (Capture myCapture) { 
  myCapture.read (); 
} 

void draw() { 
  File f = new File(dataPath(filename));
  println(dataPath(filename), f.exists());
  if(f.exists()){
  img = loadImage("portrait.jpg");
  
  if (myPort.available() > 0){
    val = (char) myPort.read();
  }
  
  if (val == 48){
    sizeR = random(10,40);
    randomC = 100;
    lightness = random(50,150);
  }else{
    sizeR = 15;
    randomC = 0;
    lightness = 100;
  }
  
  pointilism();
  }else{
    image (myCapture, 0, 0); 
    
    if (myPort.available() > 0){
      val = (char) myPort.read();
    }
  
    if (val == 48){
      myCapture.stop();    
      save("data/portrait.jpg");
      background(255);
    }
  }
} 

void pointilism(){
  
  int x = int(random(img.width));
  int y = int(random(img.height));
  int loc = x + y*img.width;

  loadPixels();
  float r = red(img.pixels[loc]);
  float g = green(img.pixels[loc]);
  float b = blue(img.pixels[loc]);
  
  noStroke();
  fill(random(r-randomC,r+randomC),random(g-randomC,g+randomC),
  random(b-randomC,b+randomC),lightness);
  ellipse(x,y,sizeR,sizeR); 
}

SUPERMAN [MINI]

superman2

For my project I did a classic dodging game, modeled after retro games, with the resolution of the frame matching that of a Gameboy Advance. Controls are done through a slider (up/down movement).

ARTWORK by Adam Knuckey (my friend)

To Do for future: variable levels (after 30 or 60 seconds) with increase in speed, number of clouds, and perhaps size of clouds.

Video:

10577626_1553673304866063_2037513627_nSliderSketch

Arduino code:

int sensorPin = 0; // select the input pin for the potentiometer
int ledPin = 13; // select the pin for the LED
int sensorValue = 0; // variable to store the value coming from the sensor

void setup() 
{
//initialize serial communications at a 9600 baud rate
Serial.begin(9600);
}

void loop()
{
sensorValue = analogRead(sensorPin);// read the value from the sensor:
Serial.println(sensorValue);
delay(25);
}

Processing code:

import processing.serial.*;
import gifAnimation.*;

int[][] clouds = new int[10][4];
Animation man;

Serial myPort;  // Create object from Serial class
String val;     // Data received from the serial port
float pos = 0;
int size;
int speed;
boolean gameOver;
int level;
int millis;
int score;
PImage cld1;
PImage cld2;
int manX;



void setup() {
  size(240, 160);
  String portName = Serial.list()[9]; //change the 0 to a 1 or 2 etc. to match your port
  myPort = new Serial(this, portName, 9600);
  myPort.bufferUntil('\n');
  initialize();
  man = new Animation("man", 23);
}

void draw()
{

  textAlign(CENTER);
  background(#4AE8E8);
  textSize(14);
  text("Level "+level, width/7, height/8);
  textSize(11);
  text("Score: "+score, width/6, height/8+14);
  if ( myPort.available() > 0) {  
    val = myPort.readStringUntil('\n');
  } 
  if (millis>30000) {
    level++; 
    // speed++; 
    // size++;
  }
  millis = millis()%30000;
  if (val != null && !gameOver) {
    val = trim(val);
    pos = map(int(val), 295, 768, 10, height-10); //768
    pos = constrain(pos, 20, height-10);
    pos = height-pos;
    println(val+" "+pos);
  }
  noStroke();
  fill(255, 0, 0);

  man.display(width/7, pos);
  // ellipse(width/6, pos, 15, 15);

  for (int i=0; i<10; i++) {
    fill(255);
    if (clouds[i][2]==10) {
      image(cld1, width-clouds[i][0], clouds[i][1]);
    } else {
      image(cld2, width-clouds[i][0], clouds[i][1]);
    }
    //ellipse(width-clouds[i][0], clouds[i][1], size, size);
    if (manX >= width-clouds[i][0] && 
      manX < = width-clouds[i][0]+clouds[i][3]) {
      if (!gameOver) {
        score++;
      }
      if (pos <= clouds[i][1]+clouds[i][2] &&          pos+size >=clouds[i][1]) {
        gameOver=true;
        if (!gameOver) {
          score--;
        }
      }
    }
    if (!gameOver) {
      clouds[i][0]+=speed;
      if (clouds[i][0]>(width+20)) {
        clouds[i][0] = clouds[i][0]%int(random(1, 30));
        clouds[i][1]= int(random(0, height));
      }
    }
    if (gameOver) {
      textSize(28);
      text("Game Over", width/2, height/2);
      textSize(14);
      text("Press 'R' to play again", width/2, height/2+28);
    }
  }
  if (keyPressed) {
    if (key == 'r') {
      initialize();
    }
  }
}

void initialize() {
  for (int i=0; i<10; i++) {
    clouds[i][0] = int(random(-width*1.5, -10));
    clouds[i][1] = int(random(0, height));
    if (i%2==0) {
      clouds[i][2] = 10;
      clouds[i][3] = 20;
    } else {
      clouds[i][2] = 15;
      clouds[i][3] = 30;
    }
  }
  size = 9;
  manX = width/7+16;
  speed = 3;
  gameOver = false;
  level = 1;
  score = 0;
  cld1 = loadImage("cloud_small.png");
  cld2 = loadImage("cloud_big.png");
}

// Class for animating a sequence of GIFs

class Animation {
  PImage[] images;
  int imageCount;
  int frame;

  Animation(String imagePrefix, int count) {
    imageCount = count;
    images = new PImage[imageCount];

    for (int i = 0; i < imageCount; i++) {
      // Use nf() to number format 'i' into four digits
      String filename = imagePrefix + nf(i, 4) + ".gif";
      images[i] = loadImage(filename);
    }
  }

  void display(float xpos, float ypos) {
    frame = (frame+1) % imageCount;
    image(images[frame], xpos, ypos);
  }

  int getWidth() {
    return images[0].width;
  }
}

 

Sensor Display

 

In the Cave from Elizabeth Agyemang on Vimeo.
A week ago I was handed a box filled with all sorts of strange gadgets and gizmos, little parts that could be connected to an Aurdino and used to create something, anything. That’s the task I was given to do. After scrumaging through the remaining items, I found myself drawn to two objects. The first was a simple white stick like object connected to a circlular base, a sparkfun potentiometer I learned. The device immediately felt reminiscent to a flash light, the way it twisted and turned in the same smooth and intuitive fashion. It was based on this encounter, that I created my program.

Concept Quick Sketch of the concept

The Cave, is not so much a game as it is an experience, at least, that’s what I envisioned it to be. Though the program is fully functional, including the changing the flashlight size and moving its x position on the screen, their is no audio of dripping water in the cave, no eerie voices or music to set the tone. At least, not yet.

How it Works:

Essentially the player is in control of two functions. You use the large, stick potentiometer to change the size of the flashlight, and the small blue one to shift it on the x-axis.

moving Playing the game

The goal of the game is to find all three clues which you do by pointing the flashlight across the screen. Once a clue is spotted the light will flicker wildly and then the play while be moved on different y-axis of the screen in order to find the next clue.

hallo final

Problems:

noticed with the sliding potentiometer I was having issues (it kept jumping from value to value randomly), so I switched to another twisting potentiometer which fixed the problem. Also, once the player hits the third clue, I’ve been having issues changing the screen. Hopefully with some more time and coding I’ll be able to fix these issues.

diagram diagram

 

//game in which you are trying to find 3 instances of murder. Once all three are found the image reveals itself

//background image

PImage backg0;
PImage back1;
PImage back2;
PImage mid3;
PImage mid4;
PImage fro5;
PImage fro6;
PImage fro7;



float lightx;
float lighty;
float opacity=300;
float opacityb=0;
float circ1=100;
float change=0;

//locations of the clues
float clue1x;
float clue2x;
float clue3x;


//blood stains/horror
PImage dripblood;
PImage bottomstain;
PImage hands;
PImage topstain;
PImage lizzie;
PImage crimescene;

float mecirc=50;
//big circle stuff
float bigcx;
float bigcy;


float circlebig=50;
float flashclick=0;

//moving lizzie
float move=753;


float secC=0;
//game counter, counting to see if the images have bee located
//begin at the top, go to middle, then go to the bottom

//load text "Something Happened Here..."
//find the clues
float gamecounter=0;

// This Processing program reads serial data for two sensors,
// presumably digitized by and transmitted from an Arduino. 
// It displays two rectangles whose widths are proportional
// to the values 0-1023 received from the Arduino.
 
// Import the Serial library and create a Serial port handler
import processing.serial.*;
Serial myPort;   
 
// Hey you! Use these variables to do something interesting. 
// If you captured them with analog sensors on the arduino, 
// They're probably in the range from 0 ... 1023:
int valueA;  // Sensor Value A
int valueB;  // Sensor Value B
int counter= valueA;
float outcircle;
//distance between flashlight and ci
 float d;
 float mapB;
 
void setup(){
 size(838,450);
 // List my available serial ports
  int nPorts = Serial.list().length; 
  for (int i=0; i < nPorts; i++) {
    println("Port " + i + ": " + Serial.list()[i]);
  } 
   // Choose which serial port to fetch data from. 
  // IMPORTANT: This depends on your computer!!!
  // Read the list of ports printed by the code above,
  // and try choosing the one like /dev/cu.usbmodem1411
  // On my laptop, I'm using port #4, but yours may differ.
  String portName = Serial.list()[2]; 
  myPort = new Serial(this, portName, 9600);
  serialChars = new ArrayList();
 
  //drawing the background
backg0= loadImage("0Background.png");
back1= loadImage("1back.png");
back2= loadImage("2back.png");

mid4= loadImage("4middle.png");
fro5= loadImage("5front.png");

fro6= loadImage("6front.png");
fro7= loadImage("7fronts.png");
mid3= loadImage("3middle.png");


//drawing the blood stain DONT FORGET BLUR
dripblood= loadImage("blood.png");
bottomstain= loadImage("bottomstain.png");
hands= loadImage("hidhands.png");
topstain= loadImage("top stain.png");
lizzie= loadImage("lizzie2.png");
 
opacity1= map(d,0,valueA,0,250);





}
float opacity1;

void draw(){
  // Process the serial data. This acquires freshest values. 
 //value of y
 lighty=250;
  processSerial();
 //background
  image(backg0,0,0);
  image(back1,48,-11);
  image(back2,-9,-2);
  image(mid3,506,87);
  image(mid4,287,257);
  image(fro5,0,32);
  image(fro7,324,385);
  image(fro6,284,146);
  
  //blood stains/horror
image(dripblood,636,-2);
image(bottomstain,-91,31);
image(hands,161,171);
image(topstain,-91,31);
image(lizzie,move,91);

  
  noStroke();
  smooth();
float cirx=80;
//mapping


 
 //bigger circles
 
for(bigcx=11; bigcx<width; bigcx=bigcx+58){
for(bigcy=26; bigcy<height;bigcy=bigcy+47){     //if the distance between the flashlight and the circles is less then 25 and          //mapping the opacity to the distance of the light source. as it increases so does the opacity         float d= dist(valueB,lighty,bigcx,bigcy); //  opacity1= map(d,0,valueA,0,250); //    if ((dist(valueB,lighty,bigcx,bigcy)<25)&&(valueA>=cirx)){
//      opacity1=0;
//      
//    }else{
//     opacity1=map(d,0,valueA,0,250);
//      
//    }
  
    if (valueA< =7){       opacity1=248;     }else{       opacity1=map(d,0,valueA,0,250);            }          fill(0,0,0, opacity1);//opacity1    ellipse(bigcx,bigcy,cirx,cirx); //  println("opacity1", opacity1, "valB:", valueB, "valA", valueA);               //locations of the clues       clue1x=248; clue2x=656; clue3x=832;               while ((valueB==clue3x)&&(gamecounter>2)){
     opacity1=0;
     
   }
   }
        
   //if the flashlight is on the clue add to counter and move to next line in image
  if((dist(valueB,lighty,clue1x,254)< =5)||(valueB==clue1x)){         secC= random(15);       gamecounter=1;           }else{     secC=secC;      lighty=lighty;        }    if (gamecounter==1){      lighty=10;                }    if ((dist(valueB, lighty, clue2x,13)<5)||(valueB==clue2x)&&(gamecounter>=1)&&(lighty==10)){
     
     secC= random(40);
     gamecounter=2;
     lighty=130;
          
   }
   
   if ((dist(valueB, lighty, clue3x,13)<5)||(lighty==130)||(gamecounter>=2) ){
     lighty=130;
     
     secC= random(40);
     gamecounter=3;
     
   }if((gamecounter==2)&&(valueB==clue3x)){
     gamecounter=3;
     opacity1=random(100);
     
   }
   if((gamecounter==3)&&(valueB==clue3x)){
     
    move= random(753);
     
     
   }



   
   
   
 }

 
 
   fill(255,200,0,0);
   rect(clue1x,254,5,5);
   rect(clue2x,13,5,5);
   rect(clue3x,140,5,5);
  //flashlight
    //change the blue, ie the last number to lighten it
  fill(254,255,0,25*1/2*secC);
  //the size of the flashlight is being mapped to the mouse
  lightx= map(mouseX,0,width,0,850);
//   lighty= map(valueB,0,height,0,200);
   
  ellipse(valueB, lighty,flashclick,flashclick);
  //main center circle
fill(254,255,0,secC);
  ellipse(valueB,lighty,valueA,valueA);
  //outside rim
  fill(254,255,0,secC*1/2);
  outcircle= valueA+(valueA+(valueA*1/2));
  ellipse(valueB,lighty, outcircle,outcircle);
  //changing the opacity of the flashlight
        if (valueA< =7){  
 secC=0;         
  counter=valueA;}         
 while((valueA>counter)){
         secCsecC+ 5;
          counter=valueA;
          
        }
        
         while (valueA 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 == 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);}         
// 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);
    }
  }
}

Aurdion code:

// program reads two analog signals from two potentiometers 
 
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
 
void setup() {
  Serial.begin(9600);  // initialize serial communications    
}
 
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    
 
  Serial.print ("A"); 
  Serial.println (sensorValue0); 
  Serial.print ("B"); 
  Serial.println (sensorValue1);  
 
  delay (50);   // wait a fraction of a second 
}
 
/*
 
*/