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
}