import processing.serial.*; //int end = 10; //the number 10 in ASCII for linefeed (end of serial.println), will use later String serial; //declare a new string called "serial" Serial myPort; //the serial port, this is a new instance of the serial class (an object) Serial myPortOut; int time = 1; int feed = 1025; int something = 1; int val; int i = 0; int debug = 0; int mylimit = 60; // Value for checking accelaration - YOur desire to hear the sound int[] initValues = new int[]{0,0,0,0}; int[] abs = new int[]{0,0,0,0}; void checkValues(int[] values, int limit) { for (int i = 0; i <= 3; i++) { abs[i] = abs(values[i] - initValues[i]); if (abs[i] > limit) { sendSignal(i); } println("abs"+i+"=" + abs[i]); initValues[i] = values[i]; } } void sendSignal(int axis) { if (axis == 1) { // make sound X println("X"); } else if (axis == 2) { // make sound Y println("Y"); } else if (axis == 3) { // make sound Z println("Z"); } } void setup() { println(Serial.list());//list all available ports myPort = new Serial(this, Serial.list()[1], 9600);//open the port you're using at the rate you want myPortOut = new Serial(this, Serial.list()[0], 9600); //myPort.bufferUntil('\n'); //don't generate serialEvent() Unless you get a newline characteer // background(0); // initial background // size(400,400); } void draw(){ if (myPort.available() > 0) { //as long as there is data coming in from serial port, read it and write it debug += 1; String inString = myPort.readStringUntil('\n'); //println(debug + ":" + inString); if (inString != null) { inString = trim(inString); int[] val = int(split(inString, "\t")); if (val.length >= 4) { print(debug + ":"); print(val[0]); print(","); print(val[1]); print(","); print(val[2]); print(","); print(val[3]); println(",end-of-values"); checkValues(val, mylimit); } } delay(10); } if (11 150) { myPortOut.write('C'); } else { myPortOut.write('Z'); } if (11 150) { myPortOut.write('G'); } else { myPortOut.write('Z'); } /* if (11 150) { myPortOut.write('K'); } else { myPortOut.write('Z'); } */ myPortOut.write(abs[0]); myPortOut.write(abs[1]); myPortOut.write(abs[2]); myPortOut.write(abs[3]); // myPortOut.write('/n'); }