Assignment: Sensing PART II: Force Sensitive Resistors and Photocells
Collaborators:
Assignment: Sensing PART II: Force Sensitive Resistors and Photocells
Collaborators:
My interface is designed to emulate the way in which people knock on doors, and provide electronic feedback on the process.
For my physical interface, I used a potholder to accept force from across a wide area. A small piece of folded paper focused the force onto the FSR. The entire contraption was then mounted to the wall.
The visualization begins with an image of a door, a text overlay, and a working clock. When the user knocks on the physical representation of the door, the word "knock" appears on the virtual door. The color of the word is determined by the force of the knock. Harder knocks result in whiter text.
In addition, an LED on the Arduino board is linked to the FSR for another form of feedback. Harder knocks result in brighter flashes.
Materials
- Arduino
- FSR
- LEDs
- Resistors
- Potholder
- Paper (folded between potholder and FSR)
Code
Arduino
/* FSR Arduino code * Takes input from an FSR * Interacts with Processing program to create an output * code from: http://courses.ischool.berkeley.edu/i262/f09/sites/default/files/LEDFade... */ int sensorPin = 0; //selects the input pin for the sensor int ledPin = 9; // select the output 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(sensorPin); // read the value from the sensor, 0-1023 analogWrite(ledPin, val/4); // analogWrite (dimming the LED) can be between 0-255 Serial.println(val/4); // writing the value to the PC via serial connection delay(50); // rest a little... }
Processing
//Door image from http://www.flickr.com/photos/weeping-willow/2960664141/ //Clock adapted from http://processing.org/learning/basics/clock.html //Text with apologies to Sartre. //Image and font setup PImage bg; int a; int messageOffset = 20; PFont fontA; //Note: you must create fonts before use PFont fontB; PFont fontC; //Arduino connection settings import processing.serial.*; String portname = "/dev/tty.usbserial-A7006RZQ"; Serial port; String buf=""; int cr = 13; // ASCII return == 13 int lf = 10; // ASCII linefeed == 10 //Clock variables & settings int clockXLoc = 190; //set horizontal position int clockYLoc = 105; //set vertical position int clockRadius = 20; //set radius of clock int clockSecHandLen = (clockRadius * 9 / 10); int clockMinHandLen = (clockRadius * 3 / 4); int clockHourHandLen = (clockRadius * 5 / 8); int clockXLen = clockRadius * 2; int clockYLen = clockRadius * 2; void setup() { size(375,500); bg = loadImage("door.jpg"); fontA = loadFont("HelveticaNeue-Bold-48.vlw"); fontB = loadFont("HelveticaNeue-Bold-36.vlw"); fontC = loadFont("HelveticaNeue-Bold-14.vlw"); textFont(fontA, 48); port = new Serial(this, portname, 9600); background(bg); //draws background fill(200); text("no", messageOffset, 410); fill(255); text("exit", messageOffset, 450); smooth(); textFont(fontC, 12); } void draw() { } void serialEvent(Serial p) { //not sure about this String inString = p.readStringUntil('\n'); println(inString); if (inString != null) { inString = trim(inString); float inByte = float(inString); if (float(inString) >=60) { fill(float(inString)); println("c >= 50; c = "+inString); //****** text("knock", random(110, 230), random(170,440)); } } else { //draws clock fill(80); noStroke(); ellipse(clockXLoc, clockYLoc, clockXLen, clockYLen); //gray outer ellipse float s = map(second(), 0, 60, 0, TWO_PI) - HALF_PI; float m = map(minute() + norm(second(), 0, 60), 0, 60, 0, TWO_PI) - HALF_PI; float h = map(hour() + norm(minute(), 0, 60), 0, 24, 0, TWO_PI * 2) - HALF_PI; stroke(255); strokeWeight(1); //seconds line(clockXLoc, clockYLoc, cos(s) * clockSecHandLen + clockXLoc, sin(s) * clockSecHandLen + clockYLoc); strokeWeight(2); //minutes line(clockXLoc, clockYLoc, cos(m) * clockMinHandLen + clockXLoc, sin(m) * clockMinHandLen + clockYLoc); strokeWeight(4); //hours line(clockXLoc, clockYLoc, cos(h) * clockHourHandLen + clockXLoc, sin(h) * clockHourHandLen + clockYLoc); strokeWeight(2); for (int a = 0; a < 360; a+=6) { float x = clockXLoc + ( cos(radians(a)) * clockSecHandLen ); float y = clockYLoc + ( sin(radians(a)) * clockSecHandLen ); point(x, y); } } }