//micDetectP.pde import processing.serial.*; Serial port; D2GraphR tG; //2Dgraph Class int width = 600, height = 400; boolean mousePressBtn = false; int sdata = 0; void setup() { size(600, 400, P3D); frameRate(60); background(255); tG = new D2GraphR(int(width*0.75), int(height*0.75), "Time[S]", "Output[V]"); println("Available serial ports:"); //println(Serial.list()); // Please input your COM port port = new Serial(this, "COM3", 115200); } void draw(){ fill(0); textSize(16); text("Please click !", 200, 30); if( mousePressBtn ){ fill(255, 0, 0); text("Sampling!", 330, 30); } else { fill(255, 255, 255); noStroke(); rect(280, 20, 100, 30); } tG.graphPointDraw((float)sdata); } void serialEvent(Serial p){ if( port.available( )> 0){ sdata = port.read(); println(sdata); if( mousePressBtn ){ port.write(65); //sign for Arduino } } } void mousePressed(){ if( !mousePressBtn ){ port.write(65); mousePressBtn = true; } else { mousePressBtn = false; } } // class D2GraphR -------------------------------------------- class D2GraphR { int X_LENGTH, Y_LENGTH; String X_LABEL, Y_LABEL; float[] y; //data float maxRange; int xsp, ysp; //space x, y D2GraphR(int _X_LENGTH, int _Y_LENGTH, String xL, String yL) { X_LENGTH = _X_LENGTH; Y_LENGTH = _Y_LENGTH; X_LABEL = xL; Y_LABEL = yL; xsp = int((width-X_LENGTH)/2); ysp = int((height-Y_LENGTH)/2); y = new float[X_LENGTH]; for (int i = 0; i < X_LENGTH; i++) { y[i] = 0; } maxRange = 255; labels(); } void graphPointDraw(float _y) { y[X_LENGTH - 1] = _y; for (int i = 0; i < X_LENGTH - 1; i++) { y[i] = y[i + 1]; } pushMatrix(); { clear(); translate(xsp, Y_LENGTH/2+ysp); scale(1, -1); strokeWeight(1); for (int i=0; i