/* Processing code:
 *
 * Text display on screen of data (numbers) sent to the serial port.
 * (Font created and integers translated to ASCII for display)
 *--------------------------------------------------------------*/
 import processing.serial.*;
 Serial myPort;
 PFont f;                  // font object (for graphical text)
 int serialGet;            // Integer variable for storing serial data
 String strData = "Start"; // String variable for drawing alphanumerics
 
  void setup() {
  size(350, 200);
  background(200, 210, 0);   // color (r, g, b)
  println(Serial.list());    // Diagnostic: gives list of ports
  myPort = new Serial(this, Serial.list()[2], 9600);

  smooth();
  //-----  Create graphical font -------
  printArray(PFont.list());
  f = createFont("Verdana", 42);
  textFont(f);
  textAlign(CENTER);
  fill(90, 100);             // Set the gray value and alpha of graphics 
  } 
 
//--Here the draw loop uses serialGet variable fetched by serialEvent()
 
  void draw() {  
    background(200, 210, 0);     // clear the screen
    rect(50, 50, serialGet, 50); // draw rectangle: upper Lt x, y, Lower Rt x, y
    strData = str(serialGet);    // cast serial data to a String, store in "strData"
    text(strData, 170, 140);     // draw text (strData) on the screen at x, y
 }             

//---- 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 serialData) {
   serialGet = serialData.read();
// println(serialGet);
}