import processing.serial.*; Serial myPort; // The serial port int iter = 0; float x = 500; float y = 500; void setup () { // set the window size: size(1000, 1000); myPort = new Serial(this, Serial.list()[0], 9600); //Open port // A serialEvent() is generated when a newline character is received : myPort.bufferUntil('\n'); background(0); //set inital background } void draw () { //Drawing a line from center to point. stroke(127, 34, 255); //stroke(150); //stroke color line( width/2, height/2, x, y); stroke(250); point(x,y); } void serialEvent (Serial myPort) { // get the ASCII string: String inString = myPort.readStringUntil('\n'); // Skip first iteration if (iter == 1){ String splitted[] = split(inString,' '); String inString1 = splitted[0]; String inString2 = splitted[1]; if (inString1 != null || inString2 != null || inString1 != " " || inString2 != " ") { inString1 = trim(inString1); // trim off whitespaces. inString2 = trim(inString2); float dist = float(inString1); // convert to a number. float angl = 0.9*float(inString2); if (!Float.isNaN(dist) || !Float.isNaN(angl)){ dist = map(dist, 0, 4, 0, width); //angl = map(angl, 0, 1023, -3.14, 3.14); //map to the screen height. x = width/2 + dist*cos(angl*1.115); y = height/2 + dist*sin(angl*1.115); } } } iter = 1; }