[Description]
- Using FSR, change the size of cube in the 3D space.
[Components]
- FSR X 1
- Resistor (R-R-B-G) X 1
- LED X 1
[Processing Code]
import processing.serial.*;
String portname = "COM3";
Serial port;
String buf="";
int cr = 13; // ASCII return == 13
int lf = 10; // ASCII linefeed == 10
int fsr = 0;
void setup() {
size(400, 400, P3D);
fill(204);
port = new Serial(this, portname, 9600);
}
void draw() {
}
void drawCube(int s) {
lights();
background(0);
camera(30.0, 120.0, 180.0, // eyeX, eyeY, eyeZ
0.0, 0.0, 0.0, // centerX, centerY, centerZ
0.0, 1.0, 0.0); // upX, upY, upZ
noStroke();
box(120 - s/4); // Change the size of cube with FSR
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) {
fsr = int(buf);
println("fsr="+fsr);
drawCube(fsr);
buf = "";
}
}