Hi Cedric,
Again thanks for your support.
here is the code, its a little all over the place as its in development!
I'm trying to read in a string from the serial port and then print it out in draw(), the string is printing out ok, i just cant get the text command to work!
Thanks
Pete
Code:
//Processing code to run with this example:
import processing.serial.*; // import the Processing serial library
Serial myPort; // The serial port
float bgcolor; // Background color
String fgcolor; // Fill color
String xpos, ypos; // Starting position of the ball
char sender = 'A';
PFont font;
String s;
String mystring_ext;
void setup() {
size(200,200);
// List all the available serial ports
println(Serial.list());
// I know that the first port in the serial list on my mac
// is always my Arduino module, so I open Serial.list()[0].
// Change the 0 to the appropriate number of the serial port
// that your microcontroller is attached to.
myPort = new Serial(this, Serial.list()[1], 9600);
// read bytes into a buffer until you get a linefeed (ASCII 10):
myPort.bufferUntil('\n');
// draw with smooth edges:
smooth();
}
void draw() {
background(0);
fill(150);
font = loadFont("Aharoni-Bold-20.vlw");
textFont(font);
background (0);
//text("xpos", 10, 20);
//text("ypos", 10, 40);
//text("fgcolor", 10, 60);
String s = "The quick brown fox jumped over the lazy dog.";
text(mystring_ext, 0, 0, 200, 200);
fill(0, 102, 153);
}
// serialEvent method is run automatically by the Processing applet
// whenever the buffer reaches the byte value set in the bufferUntil()
// method in the setup():
void serialEvent(Serial myPort) {
// read the serial buffer:
String myString = myPort.readStringUntil('\n');
// if you got any bytes other than the linefeed:
myString = trim(myString);
mystring_ext = myString;
// split the string at the commas
// and convert the sections into integers:
String sensors[] = (split(myString, ','));
// print out the values you got:
for (int sensorNum = 0; sensorNum < sensors.length; sensorNum++) {
print(sensors[sensorNum] + " ");
}
// add a linefeed after all the sensor values are printed:
println();
if (sensors.length > 1) {
xpos = sensors[0];
ypos = sensors[1];
fgcolor = sensors[2];
}
// send a byte to ask for more data:
if (sender == 'A'){
sender = 'B';}
else{
sender = 'A';}
myPort.write(sender);
}