* To Instructors: Because of high fever, I won't be able to come to the class today. I will also improve the assignment below as soon as I get better. Thanks for your consideration. - Seung Wook Kim
[Description]
- Using FSR, move the camera in the 3D space up and down.
[Components]
- FSR X 1
- Resistor (R-R-B-G) X 1
- LED X 1
[Processing Code]
import processing.serial.*;
String portname = "COM11";
Serial port;
String buf="";
int cr = 13; // ASCII return == 13
int lf = 10; // ASCII linefeed == 10
void setup() {
size(400, 400, P3D);
fill(204);
port = new Serial(this, portname, 9600);
}
void draw(int val) {
lights();
background(0);
// Change height of the camera with mouseY
camera(30.0, val, 220.0, // eyeX, eyeY, eyeZ
0.0, 0.0, 0.0, // centerX, centerY, centerZ
0.0, 1.0, 0.0); // upX, upY, upZ
noStroke();
box(90);
stroke(255);
line(-100, 0, 0, 100, 0, 0);
line(0, -100, 0, 0, 100, 0);
line(0, 0, -100, 0, 0, 100);
}
// called whenever serial data arrives
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);
draw(val);
buf = "";
}
}