import processing.serial.*; //--- import serial library
Serial myPort;              // Create Serial object, name it "myPort"
String serialString;        // variable for storing serial data
int val;                    // for storing number re-cast from string 

void setup() {   size(400, 400);    // Set size of canvas   
println(Serial.list());   // -Gives list of available ports   
myPort = new Serial(this, Serial.list()[2], 9600); //-- Change to your port number
}

void draw(){   
println(val);       //-- Write number to the interface output window
background(val);    //-- Set grey scale background color (0 - 255)
}                   //-- End of draw loop

//---- The SerialEvent function runs continuously in the background and
//---- stores new values whenever new data comes in on the serial port (USB)
void serialEvent(Serial myPort) {   
serialString = myPort.readStringUntil(10); // Read until end of line character
if (serialString != null) {     serialString = trim(serialString);      
val = int(serialString);     
println(val);   }             //- end if()
}                             //- end function definition
