8th Inter Lab Documentation

The code is below:

import processing.serial.*;
Serial mp;
String s;
float x,y,dx,dy,px,py,ppx,ppy;

void setup() {
size(800,600);
background(255);
printArray(Serial.list());
mp = new Serial(this, Serial.list()[8], 9600);
mp.clear();
s = mp.readStringUntil( 10 ); 
s = null;
px = 0;
py = 600;
}

void draw() {
strokeWeight(2);
while (mp.available() > 0) {
s = mp.readStringUntil( 10 );
if (s!= null) {
String[] a = split(trim(s), ",");
dx = x;
dy = y;
x = 1023-int(a[0]);
y = 1023-int(a[1]);
x = map(x,0,1023,0,800);
y = map(y,0,1023,0,600);
line(dx,dy,x,y);
/*/if (dx-x>0) {
ppx = px-1;
if (ppx<0){ ppx = 0;}
} else if (dx-x<0) {
ppx = px+1;
if (ppx>width){ ppx = width;}
} 
if (dy-y>0) {
ppy = py-1;
if (ppy<0){ ppy = 0;}
} else if (dy-y<0) {
ppy = py+1;
if (ppy>height){ ppy = height;}
} 
line(px,py,ppx,ppy);
px = ppx;
py = ppy; */

}
}
}

And the actual project works like:

Leave a Reply