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
}

Comments are closed.