Description
I have multiple lines being drawn at various lengths. Their colors depend on how much light I shine on the photocell. I used my last assignment as a template for this one.
Materials
1 - photocell
1 - arduino
1- 10k resistor
Code
import processing.serial.*;
PFont caption;
String portname = "/dev/tty.usbmodem1421"; // or "COM5"
Serial port;
String buf="";
int cr = 13; // ASCII return == 13
int lf = 10; // ASCII linefeed == 10
void setup() {
size(512, 512);
noStroke();
colorMode(RGB);
fill(0.4);
port = new Serial(this, portname, 9600);
}
void draw() {
}
void drawLine (int val) {
background(0);
for(int i=0;i<512;i++) {
fill(val, 255-val, val/4);
delay(1);
ellipse(i, 100, 50, 50);
}
for(int j=0; j<256; j++) {
fill(val/4, 255-val, val);
delay(1);
ellipse(j, 300, 50, 50);
}
for(int k=0; k<158; k++) {
fill(255-val, val/2, val);
delay(1);
ellipse(k, 400, 50, 50);
}
}
// 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);
if(val > 100) {
drawLine(val);
}
buf = "";
}
}
- Login to post comments