// Example by Tom Igoe // Modified by Michihito Mizutani import processing.serial.*; Serial myPort; // The serial port String inString;//= new byte[7]; // Input string from serial port: int lf = 10; // ASCII linefeed void setup() { // List all the available serial ports: println(Serial.list()); myPort = new Serial(this, Serial.list()[1], 9600); myPort.bufferUntil(lf); } void draw() { if (inString != null){ if (inString.length() < 4) { int inInteger = Integer.parseInt(inString); println(inInteger); fill(255-inInteger,255-inInteger,255-inInteger); rect(0,0,100,200); } } } void serialEvent(Serial p) { String inBuffer = myPort.readString(); int l = inBuffer.length(); inString = inBuffer.substring(0, l-1); }