Here is the code
Arduino:
void setup()
{
Serial.begin(9600);
}
void loop()
{
Serial.println(analogRead(3));
delay(20);
}
and Processing:
import processing.serial.*;
Serial port;
String pot = ""; // Data received from the serial port
int val;
int NEWLINE = 10;
void setup()
{
size(200, 200);
String portName = Serial.list()[0];
port = new Serial(this, portName, 9600);
}
void draw()
{
if ( port.available() > 0) { // If data is available,
serialEvent(port.read());
}
print(val);
print(" / ");
}
void serialEvent(int serial)
{
if(serial != NEWLINE){
pot += char(serial);
} else {
pot = pot.substring(0, pot.length()-1);
val = Integer.parseInt(pot);
pot = "";
}
}
I just pulled from some examples and tried to simplify them. Thoughts?