ArtBus_Term

// ArtBus setup window	
 
import processing.serial.*;
PFont font;
char asciival;
String thedata = "";
Serial myPort;  // The serial port:
int i=5;
int j=0;
int k=5;
int left;
int top;
String foostring;
 
 
void setup() {
  size(700, 700);
  background(0);
  left = width-200;
  top = 50;
  stroke(255);
  line(0,top,width,top);
  line(left,0,left,height);
  // List all the available serial ports:
  println(Serial.list());
 
  // Open whatever port is the one you're using.
  myPort = new Serial(this, Serial.list()[0], 115200);
  font = loadFont("AppleGothic-12.vlw");
  textFont(font, 12);
 
  fill(255,255,0);
  noStroke();
  text("ArtBus", 20, 30);
  text("You", left+20, 30);
 
}
 
void draw() {
  while (myPort.available() > 0) {
    char asciival = myPort.readChar();
    //print(asciival);
 
    if (asciival != 10){ 
      thedata += asciival;
    }
    else{
      i++;
      if(15*i > height-15){
        i=5;
        fill(0);
        rect(0,top+5,left-5,height);
      }
      fill(255);
      text(thedata, 20, 15*i);
      thedata="";
    }
 
  }
}
 
void keyReleased() {
 
 
  /*j++;
  if(15*j > height-15){
    j=5;
    fill(0);
    rect(left+5,top+5,width-left+5,height);
  }
  fill(0,255,0);
    if((key >31)&&(key<127)){
      text(key, left+20, 15*j);
      myPort.write(key);
    }*/
  if((key >31)&&(key<127)){
    j++;
    foostring += key;
    //textAlign(CENTER);
    fill(255);
    text(key, left+20+j*10, 15*k);
  }
  if(key == ENTER){
    k++;
    print(foostring);
    //text(foostring, left+20, 15*j);
    myPort.write(foostring);
    foostring = "";
    j=0;
  }
 
  if(15*k > height-15){
    k=5;
    fill(0);
    rect(left+5,top+5,width-left+5,height);
  }
 
   // foostring = "Aa1;";
   // myPort.write(foostring);
 
}