Assignment #4 - (SQUISHY-FACE) Sensing PART II: Force Sensitive Resistors and Photocells

Assignment: Sensing PART II: Force Sensitive Resistors and Photocells

Collaborators: mcozzi

Description:

For this project, I used 'Floam' wrapped around my FSR and have the person squeeze the Floam, and watch the output of a characters face on the screen.   The characters face would change based on a gradient of 5 phases - the harder the user squeezes, the 'more pain' our character feels.

In practice it worked, but the FSR was a bit finnicky and it was hard to keep a stable reading.  I also tested this with a potentiometer and it worked great.

Components:

Floam

1 FSR

2 Resistors (110 ohm + 220 ohm)

1 LED

1 Potentiometer

Arduino Board

Bread Board

wires

 

Arduino:

/*
* one pot fades one led
* modified version of AnalogInput
* by DojoDave <http://www.0j0.org>
* http://www.arduino.cc/en/Tutorial/AnalogInput
*/
int potPin = 0;   // select the input pin for the potentiometer
int ledPin = 11;   // select the pin for the LED
int val = 0;      // variable to store the value coming from the sensor
void setup() {
Serial.begin(9600);
}
void loop() {
val = analogRead(potPin);    // read the value from the sensor, between 0 - 1024
Serial.println(val);
analogWrite(ledPin, val/4); // analogWrite can be between 0-255
}

Processing:

/*
* Arduino squishy face
* (Arduino Ball, modified)
* ----------------------
*
* Displays a character face on the screen, with a 5-phase gradient.
* Each facial expression is controlled by the input on a serial port.
* The serial port recieves input via the FSR or potentiometer.  With
* the FSR plugged in, the harder your squeeze, the 'squishier' our
* character's face becomes (i.e., more pain).
*
* This matches what Arduino's " Serial.println(val)" function
* puts out.
*
* Created 30 September 2009
* by Marco Cozzi
*/
import processing.serial.*;
// Change this to the portname your Arduino board
String portname = "/dev/tty.usbserial-A7006RZi"; // or "COM5" 
Serial port;
String buf="";
int cr = 13;  // ASCII return   == 13
int lf = 10;  // ASCII linefeed == 10
void setup() {

size(200,200);
frameRate(10);
smooth();
background(255);
noStroke();
port = new Serial(this, portname, 9600);
}

void draw() {
}

//display picture 1
void drawpic1() {
PImage pic1;
pic1 = loadImage("Picture 1.png");
image(pic1, 0, 0);
}

//display picture 2
void drawpic2() {
PImage pic2;
pic2 = loadImage("Picture 2.png");
image(pic2, 0, 0);
}

//display picture 3
void drawpic3() {
PImage pic3;
pic3 = loadImage("Picture 3.png");
image(pic3, 0, 0);
}

//display picture 4
void drawpic4() {
PImage pic4;
pic4 = loadImage("Picture 4.png");
image(pic4, 0, 0);
}

//display picture 5
void drawpic5() {
PImage pic5;
pic5 = loadImage("Picture 5.png");
image(pic5, 0, 0);
}

// called whenever serial data arrives

void serialEvent(Serial p) {
int c = port.read();
if (c != lf && c != cr) { 
buf += char(c);
}
if (c == lf) {
println("c="+c);
println("buf="+buf);
int val = int(buf);
println("val="+val);
if (val >= 0 && val < 100) {
drawpic1();
}
if (val >= 100 && val < 300) {
drawpic2();
}
if (val >= 300 && val < 600) {
drawpic3();
}
if (val >=600 && val < 800) {
drawpic4();
}
if (val >=800) {
drawpic5();
}
buf = "";
//    background(40,40,40);  // erase screen
}
}