I hate seeing something not quite answered - here's some sample code; no idea if it compiles or works, but it should give the idea of the matter:
================================================================================
Arduino code - UNTESTED
================================================================================
void setup() {
Serial.begin(9600);
}
void loop() {
int ldrvalue0 = analogRead(A0);
delay(2);
int ldrvalue1 = analogRead(A1);
delay(2);
int ldrvalue2 = analogRead(A2);
Serial.print(ldrvalue0);
Serial.print(",");
Serial.print(ldrvalue1);
Serial.print(",");
Serial.println(ldrvalue2);}
}
================================================================================
Processing code - UNTESTED
================================================================================
import processing.serial.*;
Serial myPort; // The serial port
int xPos = 1; // horizontal position of the graph
int height0 = 0;
int height1 = 0;
int height2 = 0;
int width = 400;
void setup () {
// set the window size:
size(width, 300);
// List all the available serial ports
// if using Processing 2.1 or later, use Serial.printArray()
println(Serial.list());
// I know that the first port in the serial list on my mac
// is always my Arduino, so I open Serial.list()[0].
// Open whatever port is the one you're using.
myPort = new Serial(this, Serial.list()[0], 9600);
// don't generate a serialEvent() unless you get a newline character:
myPort.bufferUntil('\n');
// set inital background:
background(0);
}
void draw () {
// everything happens in the serialEvent()
}
void serialEvent (Serial myPort) {
// get the ASCII string:
String inString = myPort.readStringUntil('\n');
if (inString != null) {
// trim off any whitespace:
inString = trim(inString);
// split up by the separator
String[] v = splitTokens(inString, ",");
// convert to an int and map to the screen height:
float inByte0 = float(v[0]);
float inByte1 = float(v[1]);
float inByte2 = float(v[2]);
inByte0 = map(inByte0, 0, 1023, 0, height0);
inByte1 = map(inByte1, 0, 1023, 0, height1);
inByte2 = map(inByte2, 0, 1023, 0, height2);
// draw the lines (overlapping each other):
stroke(0, 0, 255); // blue
line(xPos, height0, xPos, height0 - inByte0);
stroke(0, 255, 0); // green
line(xPos, height1, xPos, height1 - inByte1);
stroke(255, 0, 0); // red
line(xPos, height2, xPos, height2 - inByte2);
// at the edge of the screen, go back to the beginning:
if (xPos >= width) {
xPos = 0;
background(0);
}
else {
// increment the horizontal position:
xPos++;
}
}
}
Note that one part is for the Arduino, the other is for Processing (running on the PC). This code is basically a "mash-up" from the following places:
...plus a bit of other various online consulting via google. I don't know much about Processing, and I have never used it, but it seems straightforward enough. Hopefully, this bit of code will help someone, or at least spur people on in this thread to refine and correct any mistakes I have probably made.
Cheers!