Stop Working!

Assignment: Sensing PART II: Force Sensitive Resistors and Photocells

Collaborators:

Description

I wanted to create a device that I could use every day. Often, I’m working in my office and my girlfriend is working in hers, and I’d like to let her know that I’m thinking about her, but don’t want to, or can’t, visit. I’d like a device that reminds me of her, that I can interact with, and that will let us both know that I’m thinking of her. For this project, I have a felt likeness of her face stuffed with batting enclosing the FSR. When I squeeze her face, the processing code displays a picture for a duration inversely proportional to how long the program’s been running and runs a ruby script which sends her an email.

Materials

  • Felt
  • Batting
  • FSR
  • resistor
  • wires
  • arduino

Programs

Processing

import processing.serial.*;

String portname = "/dev/tty.usbserial-A7006SoU"; // or "COM5"
Serial port;
String buf="";
int cr = 13;  // ASCII return   == 13
int lf = 10;  // ASCII linefeed == 10
PImage display = loadImage("http://img.skitch.com/20091001-qu8juwd2mpifw26nn4n563g3u6.jpg");
float press_time = 0;
float last_press_time = 0;
float display_constant = 5000;
Boolean isGrey = true;
PFont helvet;

void setup() {
  size(640,480);
  frameRate(30);
  smooth();
  helvet = loadFont("Helvetica-48.vlw");
  background(153);
  noStroke();
  port = new Serial(this, portname, 9600); 
}
void draw() {
}
// called whenever serial data arrives
void serialEvent(Serial p) {
  int c = port.read();
  if (c != lf && c != cr) {
    buf += char(c);
  }
  if (c == lf) {
    int val = int(buf);
    //println("val = " + val);
    buf = "";
    press_time = millis();
    if (val > 400 && last_press_time < press_time - 500)
    {
      image(display, 0, 0);
      open("/usr/local/bin/ruby /Users/ben/Code/tui/mail.rb");
      isGrey = false;
      last_press_time = press_time;
    }
  }
  if(isGrey == false)
  {
    if(last_press_time + (display_constant * (display_constant / last_press_time)) < press_time)
    {
      isGrey = true;
      background(153);
      textFont(helvet, 44); 
      text("Stop working!", 200, 200);
    } 
  }
}

Arduino

int in = 0;
int value = 0;

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

void loop() {
  value = analogRead(in);
  Serial.println(value);
  delay(100);
}

Ruby

require 'rubygems'
require 'tlsmail'

content = <<EOF
From: EMAIL@gmail.com
To: EMAIL@gmail.com
Subject: Thought of you at #{Time.now.strftime("%A %B %d, %Y")}
Date: #{Time.now.rfc2822}

Almost finished working!

EOF

Net::SMTP.enable_tls(OpenSSL::SSL::VERIFY_NONE)
Net::SMTP.start('smtp.gmail.com', 587, 'gmail.com', 'EMAIL@gmail.com', 'PASSWORD', :login) do |smtp|
  smtp.send_message(content, 'EMAIL@gmail.com', 'EMAIL@gmail.com')
end
20090930-IMG_1791-1
Uploaded with plasq's Skitch!