Announcements

November 24, 2007
Reading for November 27th, are now posted. Enjoy!

October 2, 2007
To upload your thoughtless acts, create a new assignment page like any other lab. You'll see "Thoughtless Acts" listed as one of the assignment options.

May 24, 2008
This site has been archived and is no longer editable. Stay tuned for the next version, coming in the fall!


Revision of Lab 4 from Wed, 09/26/2007 - 23:53

Project Members: 
Eun Kyoung Choe

Description





Hardware Components Used

3 LED
3 Resistors
2 Potentiometers
Arduino Board
Breadboard
Wires

Arduino Code

/*
*  09/26/07
*  Tangible User Interfaces
*  Lab 4 Sensors: Force sensitive resistors and photocells
*  Eun Kyoung Choe
*/

// variables for input pin and control LED
  int analogInput = 3;
  int LEDpin1 = 13;
  int LEDpin2 = 12;
  int LEDpin3 = 11;
 
// variable to store the value
  int value = 0;
 
// a threshold to decide when the LED turns on
  int threshold = 512;
  void setup(){

// declaration of pin modes
  pinMode(analogInput, INPUT);
  pinMode(LEDpin1, OUTPUT);
  pinMode(LEDpin2, OUTPUT);
  pinMode(LEDpin3, OUTPUT);
   
// begin sending over serial port
  beginSerial(9600);
}

void loop(){
// read the value on analog input
  value = analogRead(analogInput);

// if value greater than threshold turn on LED
  if (value < threshold){
  digitalWrite(LEDpin1, LOW);
  digitalWrite(LEDpin2, LOW);
  digitalWrite(LEDpin3, LOW);  
}

else{
   digitalWrite(LEDpin1, HIGH);
   digitalWrite(LEDpin2, HIGH);
   digitalWrite(LEDpin3, HIGH);
}
// print out value over the serial port
  printInteger(value);

// and a signal that serves as seperator between two values
  printByte(10);

// wait for a bit to not overload the port
  delay(10);
}

Processing Code

/*
*   09/26/07
*  Tangible User Interfaces
*  Lab 4 Sensors: Force sensitive resistors and photocells
*  Eun Kyoung Choe
*
*  Reads the values which represent the state of a FSR sensor
*  from the serial port and draws a graphical representation.
*/

// importing the processing serial class
import processing.serial.*;

// definition of window size and framerate
  int xWidth = 500;
  int yHeight = 500;
  int fr = 30;

// attributes of the display
  boolean output = false;
 
// variables for serial connection, portname and baudrate have to be set
  Serial port;
  String portname = "/dev/tty.usbserial-A4001nXx"; 
  int baudrate = 9600;
  int value = 0;
  String buf="";
  int value1 = 0; 

// variables to draw graphics
  int x, y, cursorSize;
  int cnt = 6;
 
// hit the space key and erases the screen
void keyPressed(){
  if (key == ' '){
    background(153);
  }
}

void setup(){
 
  // set size and framerate
  size(xWidth, yHeight);
  background(153);
  frameRate(fr);
  // establish serial port connection     
  port = new Serial(this, portname, baudrate);
  println(port);
  noStroke();
  smooth();
}

void drawLDRState(){
 
  cnt = int(random(1,5));
  cursorSize = 5 + cnt*(value1/20); 
  x=int(random(0,500));
  y=int(random(0,500));
  float gray = value1/4;
  fill(gray,120);
  ellipse(x,y,cursorSize,cursorSize);
}

void serialEvent(int serial){

  if(serial!=10) {       
    buf += char(serial);         
    } else {
    value1 = int(buf);
    buf="";
    }
    if(output) println("LDR: "+value1);
}

void draw(){
  while(port.available() > 0){
        value = port.read();
        serialEvent(value);
    }
  drawLDRState();
}


Photo


Powered by Drupal - Design by Artinet