import processing.serial.*; Serial myPort; // Create object from Serial class int val1; int val2; int val3; int val4, lowVal, highVal, actualVal; int sensorData(){ boolean done; done = false; val2 = 0; val3 = 0; val4 = 0; myPort.clear(); while (!done){ if(myPort.available() > 0) { val1 = val2; val2 = val3; val3 = val4; val4 = (int)myPort.read(); if ((val1 ==2) & (val2 == 3) & (val3 == 4) & (val4 == 5)) done=true; } } while (myPort.available() < 1); lowVal=myPort.read(); while (myPort.available() < 1); highVal = myPort.read(); actualVal = 256*highVal + lowVal; return actualVal; } void setup() { size(200, 200); String portName = Serial.list()[0]; myPort = new Serial(this, portName, 9600); } void draw() { boolean done; int actualVal; actualVal = sensorData(); println(actualVal); background(255); if (actualVal < 10000) {fill(155, 23, 0);} else { if (actualVal > 20000) {fill(255,137,0);} else { fill(255, 55, 0);} } rect(50, 50, 100, 100); }