lab4 submission - FSR with Processing

Submitted by wendy.xue on Sat, 02/23/2013 - 19:08


The program I created in Processing colors a portion of a half circle based on the amount of force exerted on the FSR. The FSR voltage was read in via the Serial port, and the reading was mapped to a range between 0 degree and 180 degree. The larger the voltage reading of the FSR, the larger the portion of the half circle is colored. The program decreases the colored portion when the reading decreases. 

The physical mechanism I created for concentrating the force applied on the FSR consists of a wine bottle cork, and a metal lid of a jar. When pressing on the metal lid, the force is concentrated into the small area of the cork. 


1 - Arduino
1 - 100 Ohm resistors
1 - FSR
usb cables and wire



import processing.serial.*;
Serial port;
float previousAngle = 0;
float stablizer = 10;
void setup()
 size(640, 400);
 //take the first serial port name
 port = new Serial(this, Serial.list()[0], 9600);
void draw() 
void serialEvent(Serial port)
  //read the string from the serial port
  String serialInStr = port.readStringUntil('\n');
  if (serialInStr != null)
    //trim off any whitespace
    serialInStr = trim(serialInStr);
    //convert the serial input string into a float for arc angle in degree
    float angle = float(serialInStr);
    angle = map(angle, 0,1023, 0, 180);
    float endAngle = PI + radians(angle);
   //draw pie with increased and decreased angles
    arc(width*0.5, height, width-10, width-10, PI, endAngle);
   // println(" end angle "+ endAngle);
    if (angle < previousAngle && previousAngle - angle > stablizer) 
    //erase the extra portion that was drawn for the last reading
    //only redraw the graph if there is more than 10 degree difference between the two serial readings
      arc(width*0.5, height, width-10, width-10, TWO_PI-endAngle, TWO_PI);
    previousAngle = angle;


force applier
screenshot of output of processing code
Your rating: None
Drupal theme by Kiwi Themes.