Lab 4: FSR Alarm Clock

Submitted by lwang on Tue, 02/26/2013 - 23:37

 

Objective: My idea is to attach the FSR to the insole of a house slipper that would ideally be connected to an alarm clock. I couldn't get audio output to work, but ideally the FSR would turn off audio and visualization when force over a threshold is applied. The idea is that if you want to turn off the alarm, you need to put on the slipper and step onto it to apply enough pressure. The sleeping image flashes until force is applied, then a "Good morning" image appears. 
 
 
Materials:
-FSR
-led
-wires
-resistors
-breadboard
-Slipper
 
 
Code:
 
import processing.serial.*;
// Change this to the portname your Arduino board
String portname = "/dev/tty.usbmodemfa131"; // or "COM5"
Serial port;
String buf="";
int cr = 13;  // ASCII return   == 13
int lf = 10;  // ASCII linefeed == 10
PImage sleepingImg;
    PImage awakeImg;
    int pressureAmt = 0;
    float fadeValue = 0;
    float fadeTime = 60;
int flip = 1;
    boolean reset = false;
    
    void setup() {
      size(510,500);
      // Make a new instance of a PImage by loading an image file
      sleepingImg = loadImage("sleeping.jpg");
      awakeImg = loadImage("awake.jpg");
      port = new Serial(this, portname, 9600);
    }
    
    void draw() {
      background(0);
 if(!reset){
        fadeValue += 255/fadeTime*flip;
      }
 
 
      if(pressureAmt < 600){
        // full opacity for image in background
      tint(fadeValue);
        image(sleepingImg,0,0);
      
      // change image and reset fadeValue
     if (frameCount % fadeTime == 0){
//        fadeValue = 0;
      if(reset){
              fadeValue = 0;
                   flip = 1;
        reset = false;
      } else {
flip = -flip;
}
 
      }
      } else {
tint(255);
        image(awakeImg,0,0);
        reset = true;
              
      }
    }
 
    // called whenever serial data arrives
void serialEvent(Serial p) {
  int c = port.read();
  if (c != lf && c != cr) {
    buf += char(c);
  }
  if (c == lf) {
    pressureAmt = int(buf);
    println("pressurel="+pressureAmt); 
    buf = "";
  }
}
 
awake.jpg
photo-2.JPG
sleeping.jpg
0
Your rating: None
Drupal theme by Kiwi Themes.