/* ponar01 Eric Pavey - 2011-08-08 www.akeric.com Processing sketch designed to capture serial data passed back from the ponar Arduino hardware setup, displaying the sonar\servo's distance\angle values with a 'sonar' grahical effect. */ import processing.serial.*; //-------------------------------------- // Globals: int gLf = 10; // Linefeed in ASCII String gSerialData = null; Serial gPort; // The serial port //-------------------------------------- void setup() { size(600, 400); //gRadar = createGraphics(width, height, P2D); //gRadar.beginDraw(); smooth(); background(0); //gRadar.endDraw(); frame.setTitle("Ponar - www.AKEric.com"); //------------------------------ // Setup all our serial stuff // List all the available serial ports //println(Serial.list()); gPort = new Serial(this, Serial.list()[0], 9600); gPort.clear(); // Throw out the first reading, in case we started reading // in the middle of a string from the sender. gSerialData = gPort.readStringUntil(gLf); gSerialData = null; } //-------------------------------------- void draw() { // flip everthing around: pushMatrix(); translate(width/2, height); rotate(PI); // capture the serial data: while (gPort.available () > 0) { gSerialData = gPort.readStringUntil(gLf); if (gSerialData != null) { try { String[] data = split(trim(gSerialData), " "); float deg = float(data[0]); float distance = float(data[1]); stroke(0, 255, 0); strokeWeight(8); float dis = map(distance, 0, 375, 0, height); float x = -cos(radians(deg))*dis; float y = sin(radians(deg))*dis; line(0, 0, x, y); if (dis