Make A Face & Laptop Typewriter

ldevendorf's picture

Description:

I Used Force Resistive Sensor for 2 tasks, one visual and the other mechanical.  For the visual task, I used the FSR and a Potentiometer to control the facial expression of a cartoon. 

For a mechanical task, I would suggest mounting the force sensitive resistor on the return button on your laptop or keyboard. Each time you hit "return" the "ding" from an antique type writer is heard.  The harder and longer you hit the return button, the louder the sound. The force could be distributed by a thin piece of foam between the key and the users finger in order to ensure variation in the readings.

Materials:

  • 1 Force Sensitive Resistor
  • 1 Arduino Board
  • 1 Potentiometer
  • 1 LED (to check for signals)

Arduino Code

/*
 * Resistive Sensor Input
 * Takes the input from a resistive sensor, e.g., FSR or photocell
 * Dims the LED accordingly, and sends the value (0-255) to the serial port
 */
int sensorPin = 0;  // select the input pin for the sensor
int ledPin = 11;    // select the output pin for the LED
int pot1Pin = 1;   // select the input pin for the potentiometer 1
int pot1Val = 0;   // variable to store the value coming from pot 1

int val = 0;        // variable to store the value coming from the sensor
void setup() {
  Serial.begin(9600);
}
void loop() {
 
  Serial.flush();
 
  pot1Val = analogRead(pot1Pin);   // read the value from pot 1, between 0 - 1024
  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.write(val/4);
  Serial.write(pot1Val/4);  // analogWrite (dimming the LED) can be between 0-255
 
 
  delay(50);                   // rest a little...
}

Processing Code : For Face

import processing.serial.*;


Serial port;
color  hoverColor;
int pressValue = 0;
int potValue = 0;
int pressByte = 0;
int potByte = 0;

void setup() {

  size(800, 600);
  println(Serial.list());
  port = new Serial(this, Serial.list()[0], 9600);
}

void draw() {
  noStroke();

 
  background(255);
  while (port.available() > 1) {
   
    potByte = port.read();
    pressByte = port.read();
    
    pressValue = pressByte;
    potValue = potByte;
    println("pot"+potValue);
   println("press"+pressValue);
  }
 

  //////  Yellow Background /////
  fill(248, 255, 72);
  ellipse(400, 300, 400, 400);
 
  //////  Draw the Eyes ////////
  fill(39, 206, 255);
  ellipse(300, 200, 20, 20);
  ellipse(500, 200, 20, 20);
 
  ////// Draw the Pupils ///////
//  fill(0);
//  ellipse(310-potValue, 200, 10, 10);
//  ellipse(510-potValue, 200, 10, 10);
 
  ////// Draw the Brows ///////
  stroke(0);
  strokeWeight(5);
 
  if(potValue > 65){

    //suprised eyes
    line(280, 200-potValue/4, 320, 200-potValue/4);
    line(480, 200-potValue/4, 520, 200-potValue/4);
  }else{

    //angry eyes
    line(280, 200-(65 - potValue/4), 320, 200);
    line(480, 200, 520, 200-(65-potValue/4));
  }
 
  //draw the "wow" mouth
//  noStroke();
//  fill(0);    
//  ellipse(400, 300, pressValue, pressValue);

  ///// Draw a Nose ///////
  stroke(color(162, 157, 2));
  strokeWeight(5);
  noFill();
  bezier(380, 300, 330, 350, 470, 350, 420, 300);



  ///// Draw a Smile ///////
  stroke(0);
  strokeWeight(5);
  noFill();
  float theta = (PI/255)*float(pressValue);
  float radius = 100;
  bezier(300, 350, 300+radius*cos(theta), 350+radius*sin(theta), 500-radius*cos(theta), 350+radius*sin(theta), 500, 350);

}

 

 

 

Sad Face
Happy Face
0
Your rating: None