Hi, I've set up a serial link between Arduino & Processing, moving a webcam feed around the screen using the input from two potentiometers - I've got the code to work, but it keeps running out of memory within ten seconds. I'm not really sure what's causing the problem? Could it be on the webcam side of the program?
Here's my code:
Code:import processing.opengl.*; // import the Processing opengl library
import processing.video.*; // import theProcessing video library
import processing.serial.*; // import the Processing serial library
Serial Arduino; // The serial port
Capture webCam; // The webcam feed
float xpos, ypos; // Starting position of the webcam feed
void setup() {
size(640,480,OPENGL);
// List all the available serial ports & cameras
println(Serial.list());
println(Capture.list());
webCam = new Capture(this, width/2, height/2, "USB PC Camera-WDM", 30);
Arduino = new Serial(this, Serial.list()[1], 9600);
// read bytes into a buffer until you get a linefeed (ASCII 10):
Arduino.bufferUntil('\n');
noStroke();
}
void captureEvent(Capture webCam){
webCam.read();
}
void draw() {
background(153, 153, 0);
image(webCam, xpos, ypos);
}
void serialEvent(Serial Arduino) {
// read the serial buffer:
String myString = Arduino.readStringUntil('\n');
// if you got any bytes other than the linefeed:
if (myString != null) {
myString = trim(myString);
// split the string at the commas
// and convert the sections into integers:
int sensor[] = int(split(myString, ','));
// print out the values you got:
for (int sensorNum = 0; sensorNum < sensor.length; sensorNum++) {
print("sensor " + sensorNum + ": " + sensor[sensorNum] + "\t");
}
// add a linefeed after all the sensor values are printed:
println();
if (sensor.length > 1) {
xpos = map(sensor[0], 0,width,0,width);
ypos = map(sensor[1], 0,height,0,height);
}
}
}
Any pointers would be great!