import processing.serial.*; PImage a; PImage b; PImage c; Serial myPort; // The serial port int xPos = 1; // horizontal position of the graph int drawPicture=0; int threshold= 870; int threshold2= 760; void setup () { // set the window size: size(screen.width, screen.height); a=loadImage("DV-inverse.jpg"); b=loadImage("DV.jpg"); c=loadImage("surveillance.jpg"); // List all the available serial ports println(Serial.list()); // I know that the first port in the serial list on my mac // is always my Arduino, so I open Serial.list()[0]. // Open whatever port is the one you're using. myPort = new Serial(this, Serial.list()[3], 9600); // don't generate a serialEvent() unless you get a newline character: myPort.bufferUntil('\n'); // set inital background: background(0); } void draw () { background(0); // everything happens in the serialEvent() if (drawPicture==0){ image(a, 0, 0, screen.width, screen.height); } else if (drawPicture==1){ image(c, 0, 0, screen.width, screen.height); }else{ image(b, 0, 0, screen.width, screen.height); } } void serialEvent (Serial myPort) { // get the ASCII string: String inString = myPort.readStringUntil('\n'); if (inString != null) { // trim off any whitespace: inString = trim(inString); // convert to an int and map to the screen height: float inByte = float(inString); //inByte = map(inByte, 0, 1023, 0, height); //float value=inByte; println(inByte); if (inByte>threshold) { println("GOT HERE"); drawPicture=2; } else if (inByte>threshold2) { println("ALMOST HERE"); drawPicture=1;} else { drawPicture=0; println("NOT HERE"); } } }