User login

Powered by Drupal, an open source content management system

Theory and Practice of Tangible User Interfaces

Lab 4: The Beer Coaster (FSR)

Submitted by ashley on Tue, 09/30/2008 - 22:12

Assignment: Sensing PART II: Force sensors and photocells

Collaborators:

Assignment: Sensing PART II: Force sensors and photocells
Collaborators:

Assignment: Sensing PART II: Force sensors and photocells
Collaborators:

In this project I rigged up a force sensor under a beer coaster.  The idea is that the force sensor would read the amount of beer in the bottle and display the amount graphically on screen by showing an image of a beer bottle with the liquid level clearly marked.  It worked!  If I use a straw to suck up the beer, the level of the screen liquid moves at pace with the level in the bottle.  I have enclosed a screen shot. beercoaster.jpg

 

 

/**
 * Beer Coaster. 
 * 
 * Show the amount of beer left in the bottle by measuring the pressure on the coaster.
 */
import processing.serial.*;
 
PImage bg;
PImage whiteness;
int a; 
// Change this to the portname your Arduino board
String portname = "/dev/cu.usbserial-A7006yVV"; // or "COM5"
Serial port;
String buf="";
int cr = 13;  // ASCII return   == 13
int lf = 10;  // ASCII linefeed == 10
void setup() 
{
  size(200,200);
  frameRate(30);
   // is 200 x 200 pixels.
  bg = loadImage("beerbottle.gif");
  whiteness = loadImage("white.jpg");
  port = new Serial(this, portname, 9600); 
}
void draw() 
{
  //background(bg);
}
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); 
    drawBeer(val);
    buf = "";
  }
}
// draw beer level
void drawBeer(int r) {
  background(255,204,0);
  //the whiteness image moves up or down depending on the level of liquid in the bottle
 image(whiteness, 0, -(r-670));
 //the bg image is a gif with a transparency in the shape of a bottle.
  image(bg, 0, 0);
}