Bezier editor with data from serial port

Hello! Im doing a project for school, where I’m using a pixy camera to track and send coordinates to processing so that it draws a smooth curve. I stumbled upon @Chrisir 's bezier editor, and have been trying to change the mouse-pressed inputs into my data from serial port, but it isn’t really working. I got a code whereby the line is drawn, but its a straight line instead. I’m not sure whats wrong, or where exactly to put the code where I add the co-ords from serial port into an array in regards to the og bezier editor code. If anyone can help, that would be great thank you!!

//serial port
import processing.serial.*;
Serial myPort; // Create object from Serial class
String val; // Data received from the serial port
int x,y;

ArrayList<PVector> listPV = new ArrayList();

void setup() {
  size(819,899);
  background(125);
  makeArrayList();

//port setup
String portName = Serial.list()[0];
myPort = new Serial(this, portName, 9600);
}

void draw() {
  background(155);


  
  //info from pixy 
    if ( myPort.available() > 0)  { 
      val = myPort.readStringUntil('\n'); 
      println(val); 
    } 
    if(val!=null){
       String[] xandy = splitTokens(val, " ");
     if(xandy.length==2){
       float x = float(trim(xandy[0]));
       float y = float(trim(xandy[1]));
      // circle(x, y ,10);
       listPV.add(new PVector(x, y));
       }
     }
     //listPV.add(new PVector(x, y));
     
     
         
  // show ArrayList
  showArrayList(); 
  
}


void showArrayList() {

  // show the curve 
  noFill();
  stroke(0);
  beginShape();
  int i=0;
  if (listPV.size()>0) {
    curveVertexPVector(listPV.get(i));
    for ( i = 0; i < listPV.size(); i++) {
      curveVertexPVector(listPV.get(i));
    }
    i=listPV.size()-1;
    curveVertexPVector(listPV.get(i));
  }
  endShape();

  //show the points (additionally)
  noStroke();
  float rad=3;
  for ( i = 0; i < listPV.size(); i++) {
    PVector pv=listPV.get(i);
    ellipse(pv.x, pv.y,rad, rad);
  }
}


void makeArrayList() {
  int[] coords = {
    0,0
  };
     
  // read coords[]
  for (int i = 0; i < coords.length; i += 2) {
    listPV.add ( new PVector(coords[i], coords[i + 1]));
  }
}
  

void curveVertexPVector(PVector pv) {
  curveVertex(pv.x, pv.y);
}

please also try and say println(x,y);

when your y has only small changes, you might need y=y*10; or use map()

1 Like