/* * DW added in smoothing of ultrsasound response, range multiplier rather than the width threshold */ import processing.serial.*; // width and height should be set here int xWidth = 300; int yHeight = 100; // set framerate int fr = 15; //config vars boolean output = true; //display debug // these variables are for the serial port connection object Serial portA; Serial portB; Serial portC; // String portnameA = "/dev/tty.ARD_BT_MOTO_A-Bluetooth-1"; // find the name of your serial port in your system setup! String portnameA = "COM4"; // find the name of your serial port in your system setup! String portnameB = "COM6"; // find the name of your serial port in your system setup! String portnameC = "COM8"; // find the name of your serial port in your system setup! int baudrate = 115200; // set baudrate here int valueA; // variables used to store value from serial port int valueB; // variables used to store value from serial port int valueC; // variables used to store value from serial port String buf=""; // String buffer to store serial values boolean startval = false; // startval is the start time stamp boolean endval = false; // endval is the end time stamp boolean motionA = false; //default the current motion status to *no motion* boolean motionB = false; //default the current motion status to *no motion* boolean motionC = false; //default the current motion status to *no motion* // setup timestamp parameters int secs = 0; int mins = 0; int hours = 0; int days = 0; int months = 0; int years = 0; String timestamp = ""; //format will be ISO std 2002-09-20T15:48:20.220 // setup initializes displayItems and serial port objects void setup(){ size(xWidth, yHeight); frameRate(fr); println(Serial.list()); // List all the available serial ports: portA = new Serial(this, portnameA, baudrate); println(portA); portB = new Serial(this, portnameB, baudrate); println(portB); portC = new Serial(this, portnameC, baudrate); println(portC); background(255); } // draw listens to serial port, draw void draw(){ while(portA.available() > 0){ valueA = portA.read(); serialEvent(valueA); String pirdata[] = loadStrings("pirdata.csv"); if(valueA!=10) { //ignore the line return on intere if(startval){ String newdata[] = append(pirdata, "MotoA,1," + timestamp); saveStrings("data/pirdata.csv", newdata); motionA = true; if(output) println("MotoA,1," + timestamp); } if(endval){ String newdata[] = append(pirdata, "MotoA,0," + timestamp); saveStrings("data/pirdata.csv", newdata); motionA = false; if(output) println("MotoA,0," + timestamp); } } } while(portB.available() > 0){ valueB = portB.read(); serialEvent(valueB); String pirdata[] = loadStrings("pirdata.csv"); if(valueB!=10) { //ignore the line return on intere if(startval){ String newdata[] = append(pirdata, "MotoB,1," + timestamp); saveStrings("data/pirdata.csv", newdata); motionB = true; if(output) println("MotoB,1," + timestamp); } if(endval){ String newdata[] = append(pirdata, "MotoB,0," + timestamp); saveStrings("data/pirdata.csv", newdata); motionB = false; if(output) println("MotoB,0," + timestamp); } } } while(portC.available() > 0){ valueC = portC.read(); serialEvent(valueC); String pirdata[] = loadStrings("pirdata.csv"); if(valueC!=10) { //ignore the line return on intere if(startval){ String newdata[] = append(pirdata, "MotoC,1," + timestamp); saveStrings("data/pirdata.csv", newdata); motionC = true; if(output) println("MotoC,1," + timestamp); } if(endval){ String newdata[] = append(pirdata, "MotoC,0," + timestamp); saveStrings("data/pirdata.csv", newdata); motionC = false; if(output) println("MotoC,0," + timestamp); } } } smooth(); noStroke(); fill(0,4); rect(0,0,width,height); float elipsize = random(12,40); if(motionA){ stroke(random(50,150), random(100,200), 0, 50); stroke(80); fill(random(50,150), random(150,250), 0, elipsize*2); ellipse(random(width/3), random(height), elipsize, elipsize); }else if(motionA == false){ stroke(random(150,250), 0, random(10,50), 50); stroke(80); fill(random(200,250), 0, random(10,50), elipsize*2); ellipse(random(width/3), random(height), elipsize, elipsize); }; if(motionB){ stroke(random(50,150), random(100,200), 0, 50); stroke(80); fill(random(50,150), random(150,250), 0, elipsize*2); ellipse(random(width/3,(width*2)/3), random(height), elipsize, elipsize); }else if(motionB == false){ stroke(random(150,250), 0, random(10,50), 50); stroke(80); fill(random(200,250), 0, random(10,50), elipsize*2); ellipse(random(width/3,(width*2)/3), random(height), elipsize, elipsize); }; if(motionC){ stroke(random(50,150), random(100,200), 0, 50); stroke(80); fill(random(50,150), random(150,250), 0, elipsize*2); ellipse(random((width*2)/3,width), random(height), elipsize, elipsize); }else if(motionC == false){ stroke(random(150,250), 0, random(10,50), 50); stroke(80); fill(random(200,250), 0, random(10,50), elipsize*2); ellipse(random((width*2)/3,width), random(height), elipsize, elipsize); }; delay(50); } // the serial event function takes the value of the event and store it in the corresponding variable void serialEvent(int serial){ timestamp = ""; // reset it startval = false; // reset it endval = false; // reset it if(serial!=10) { buf += char(serial); secs = second(); // Values from 0 - 59 mins = minute(); // Values from 0 - 59 hours = hour(); // Values from 0 - 23 days = day(); // Values from 1 - 31 months = month(); // Values from 1 - 12 years = year(); // 2003, 2004, 2005, etc. String monthf = ""; if(months<10){monthf = ("-" + "0"+months+"-");}else{monthf = ("-" + months+"-");}; String dayf = ""; if(days<10){dayf = ("0"+days + " ");}else{dayf = (days + " ");}; String hoursf = ""; if(hours<10){hoursf = ("0"+hours+":");}else{hoursf = (hours+":");}; String minsf = ""; if(mins<10){minsf = ("0"+mins+":");}else{minsf = (mins+":");}; String secsf = ""; if(secs<10){secsf = ("0"+secs);}else{secsf = ("" + secs);}; timestamp = (years + monthf + dayf + hoursf + minsf + secsf); if(buf.equals("1")){ startval = true; //for db endval = false; }else if (buf.equals("0")){ startval = false; endval = true; }else{ println("oops serial event but not 1 or 0"); }; //println(":"+buf+":"); buf=""; } }