//Code based on SimpleRead Example in Processing //Edit by D Conner 2016 import processing.serial.*; Serial myPort; // Create object from Serial class int val; // Data received from the serial port void setup() { size(1020, 400); String portName = Serial.list()[2];// Port 2 is Com 3 on my computer myPort = new Serial(this, portName, 9600); val =510;//The sensor has an average initial value of 510.(Max is 1024, so this is almost half.) } void draw() { if ( myPort.available() > 0) { // If data is available, String r = myPort.readString();//Read in a string String[] outputValues = split(r, " = ");//The expected input is "Out = 'value'" if(outputValues.length>1){ //Ensure the data has the Out value if(outputValues[0].equals("out")){ try { int n = Integer.parseInt(outputValues[1].trim());//Check to see if input is a integer. println(n); val = n; } catch(NumberFormatException e) {} }} }//If statement(port available) background(255); // Set background to white if (val > 510) { // If the value is greater than 510, color bar green fill(0,255,0); rect(510, 50, val-510, 100);// make a bar that is the magnitude of the strength } else { // If the value is less than 510, color bar red. Draw bar equal in magnitude. fill(255,0,0); rect(val, 50, 510-val, 100); } }