?! add lines

From Interaction Station Wiki
Jump to: navigation, search
  1. import processing.serial.Serial;
  2. //select serial port and set bauds rate
  3. static final int PORT_INDEX=2,BAUDS=9600;
  4. // create an array, a list of data will be used to store values from snesors.
  5. int[] vals= {};
  6.  
  7. void setup(){
  8.   noLoop();
  9.   frameRate(18);
  10.   final String[] ports = Serial.list();
  11.   printArray(ports);
  12.   new Serial(this, ports[PORT_INDEX], BAUDS).bufferUntil(ENTER); 
  13.  
  14.   size(1200,800);
  15.   background(0);
  16. }
  17.  
  18. void draw(){
  19.  
  20.    print("x=");
  21.    println(vals[0]); 
  22.    print("Y=");
  23.    println(vals[1]); 
  24.    print("Button=");
  25.    println(vals[2]); 
  26.  
  27.  //the ellipse  
  28.    noStroke();
  29.    fill(0,80,80);
  30.    ellipse(width/2,height/2,200,200);
  31.  
  32.  
  33. // the lines
  34.    strokeWeight(5);
  35.    stroke(250,250,140);
  36.  //  line(width/2,height/2,mouseX,mouseY);
  37.    line(width/2,height/2,vals[0],vals[1]);
  38.    if(vals[2]>0){
  39.    background(0);
  40.    }
  41.  
  42.     }
  43. void serialEvent(final Serial s) {
  44. // split the string from the serial port into 3 integers and store it in the list.
  45.   vals = int(splitTokens(s.readString()));
  46.   redraw = true;
  47. }