Wednesday, October 20, 2004

Processing Shoe Code

float[] data = new float[3]; // create 2 space data array. 1) Potentiometer and 2) photocell
int index=0;
float xpos,ypos;
int bck;

int[] dotsXpos = new int[30];
int[] dotsYpos = new int[30];
int dots;

void setup() {
background(0);
size(305,305);
beginSerial(); //begin serial communication thing
serialWrite(65); //talk to PIC . like saying hello
}

void loop() {

fill(0,140,140);
noStroke();
ellipse(xpos,ypos,3,3);

for (int i=0;i if ((dotsXpos[i] != 0) && (dotsYpos[i] != 0)) {
fill(255,255,0);
noStroke();
ellipse(dotsXpos[i],dotsYpos[i],10,10);
}
}

if (bck==1) {
dotsXpos[dots] = int(xpos);
dotsYpos[dots] = int(ypos);

if (dots>30) {

dots= 0;
}
else {
dots = dots++;
}
}
}

void serialEvent() { //automatic serial listener
data[index] = serial; // save messages to data array
index=index+1; // increment serial counter

if (index==3) { // both messages received
ypos = 255 - float(data[0]); // rename the first message to xpos
xpos = float(data[1]);
bck = int(data[2]); //save photocell value
serialWrite(65); // responsd back to PIC
index = 0; // reset serial counter to zero
}

}

0 Comments:

Post a Comment

<< Home