Description
In this lab, I fit the force sensitive resistor between two airpacks. Upon compression, a rose is generated in Processing. This rose is created from arcs against a gradient background.
Materials
- Arduino, LED, jumper, cables
- Processing
- Force sensitive resistor
- Air packs
import processing.serial.*;
String portname = "/dev/cu.usbmodem1421";
Serial port;
String buf="";
int cr = 13;
int lf = 10;
int serialVal = 0;
int shift = 0;
void setup() {
size(800,800,P3D);
port = new Serial(this, portname, 9600);
noStroke();
colorMode(RGB, 400);
for (int i = 200; i < 400; i++) {
for (int j = 200; j<400; j++) {
stroke(i,j,0);
point(i,j);
}}}
//}
//
void draw() {
noStroke();
colorMode(RGB, 400);
for (int i = 0; i < 800; i++) {
for (int j = 0; j<800; j++) {
stroke(i,j,0);
point(i,j);
}
}
stroke(255,0,255);
noFill();
//ellipse(150,150,serialVal, serialVal);
genRose((int) (serialVal*0.7),0, 350, 350);
genRose((int) (serialVal*0.5), (int) HALF_PI, 350, 350);;
if (serialVal > 400) {
genRose((int) (serialVal*0.5) ,0, 600, 600);
genRose((int) (serialVal*0.3), (int) HALF_PI, 600, 600);;
if (serialVal>500) {
genRose((int) (serialVal*0.5) ,0, 200, 200);
genRose((int) (serialVal*0.3), (int) HALF_PI, 200, 200);;
genRose((int) (serialVal*0.3) ,0, 700, 700);
genRose((int) (serialVal*0.1), (int) HALF_PI, 700, 700);;
if (serialVal > 600) {
genRose((int) (serialVal*0.3) ,0, 200, 600);
genRose((int) (serialVal*0.1), (int) HALF_PI, 200, 600);;
genRose((int) (serialVal*0.3) ,0, 600, 200);
if (serialVal > 700) {
genRose((int) (serialVal*0.1), (int) HALF_PI, 600, 200);;
genRose((int) (serialVal*0.3) ,0, 500, 500);
genRose((int) (serialVal*0.1), (int) HALF_PI, 500, 500);;
}
}
}
}
}
void genRose(int serialVal, int shift, int x, int y) {
fill(255,0,0);
arc(x,y,serialVal*0.9, serialVal, 0+shift, HALF_PI+shift);
arc(x,y,serialVal*1.1, serialVal*1.1, HALF_PI+shift, PI+shift);
fill(200,0,0);
arc(x,y,serialVal*0.9, serialVal, PI+shift, PI+HALF_PI+shift);
arc(x,y,serialVal*1.1, serialVal*1.1, PI+HALF_PI+shift, PI+PI+shift);
fill(175,0,0);
arc(x,y,serialVal/2, (serialVal/2)*0.8, 0+shift,PI+shift);
arc(x,y,serialVal/2, (serialVal/2) *0.8, (HALF_PI * 3)+shift,(PI * 2) +shift);
fill(150,0,0);
arc(x,y,(serialVal/4)*0.9, serialVal/4, 0+shift,HALF_PI+shift);
arc(x,y,(serialVal/4) *0.9, serialVal/4, PI+shift,PI+HALF_PI+shift);
fill(175,0,0);
arc(350,350,serialVal/8, (serialVal/8) *0.9, PI+HALF_PI+shift,PI+PI+shift);
arc(350,350,serialVal/8, (serialVal/8) *0.9, HALF_PI+shift,PI+shift);
}
void serialEvent(Serial p) {
int c = port.read();
if (c != lf && c != cr) {
buf += char(c);
} if (c==lf) {
serialVal = int(buf);
println("val="+serialVal);
buf= "";
}
}
Picture of the airpacks.
Now I have created a garden of roses. Using a photocell would have made more sense because sunshine correlates to flowers. But also, if I attach this FSR to a water container like my water filter (will not be bringing this to class tomorrow), I can map it to the idea of watering plants.