// Processing code:
// Simple Serial read
// adapted from example by Tom Igoe
// (Assumes ASCII data coming in serial port)
//-------------------------------------------

import processing.serial.*;

Serial myPort;          // The serial port
String serialString;  // variable for storing serial data
int val;                // for storing number re-cast from string

void setup() {
  size(200, 200);
  // List all the available serial ports:
  printArray(Serial.list());
  // Open the port you are using at the rate you want:
  myPort = new Serial(this, Serial.list()[2], 9600);
}

void draw() {
   println(val);
   background(val);
  }



//---- 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
}