// Example 19-8: Reading from serial port orig. by Daniel Shiffman // modified by Yoshio Okamoto 22th Nov.2013, 17th Mar.2014 import processing.serial.*; Serial port; // The serial port object PrintWriter output; int i = 0; int t = 0; int tt = 0; int ttt = 0; // line number float x = 0; float y = 0; int base = -480; // wave signal base line shift float px = 0; float py = 0; int data = 0; int s = 0; int m = 0; int ps = 0; int tm = 0; int tmax = 1000 * 60; // display max data 10[sec] * 60 lines String datastr; String datetimestr; String format; void setup() { size(1000,720); // window size W,H strokeWeight( 1 ); // line width background( 0 ); // clear display port = new Serial(this, Serial.list()[1], 9600); // set up port for the first serial port frameRate(100); // sampling rate/sec 100[Hz] stroke(255); // text color // initialize delay(1000); background(0); port.write('*'); } void draw() { // data file init. if (t == 0){ datetimestr = year()+"/"+nf(month(),2)+"/"+nf(day(),2)+"/Time="+nf(hour(),2) + "_" + nf(minute(),2) + "_" + nf(second(),2)+"_iFS"; // for Windows output = createWriter(datetimestr+".dat"); text( datetimestr,10,35); port.write( '*' ); } // time mark s = second(); if (s == ps) tm = 0; else if (s % 10 == 0) tm = 8; else tm = 5; ps = s; // display 1 ch stroke (50, 250, 250); // for 1ch with light blue color x = tt; y = data + base + ttt*10 - tm; // display signal if ((t==0) || (tt == 0)) point (x, y); else line (px, py, x, y); px = x; py = y; // data to text file format = String.format("%04d", data); output.println(format); tt = t % (width); ttt = int(t/width); //line number t = t+1; // renewal drawing parameter if (t>tmax){ t = 0; tt = 0; // save window image save( datetimestr+".png" ); output.flush(); // write buffer to file output.close(); // close file background(0); // reflesh window } } // for 1ch signal data input from Arduino void serialEvent( Serial p ) { if ( port.available() > 1 ) { data = port.read() + port.read() * 256 ; port.write( '*' ); } }