import processing.serial.*; Serial myPort; int val=0; int val2=0; int val3=0; int val4=0; float eps= 0.5; float window= 600; int ul1; int uh1; int dl1; int dh1; int ul2; int uh2; int dl2; int dh2; int ul3; int uh3; int dl3; int dh3; int upvalue1; int downvalue1; int upvalue2; int downvalue2; int upvalue3; int downvalue3; float filter1=0; float filter2=0; float filter3=0; int uplow=0; int high=0; void setup() { noStroke(); frameRate(30); textFont(createFont("Georgia",24)); textAlign(CENTER, CENTER); size(1000, 1000); Serial.list(); String portName = Serial.list()[4]; myPort = new Serial(this, portName, 9600); } int i=0; void draw() { int value1 = 0; int value2 =0; int value3 =0; if ( myPort.available()>0) { // If data is available, val = val2; val2 = val3; val3 = val4; val4 = myPort.read(); // read it and store it in val } if(val==1 && val2==2 && val3==3 && val4==4){ // Set background to white ul1=myPort.read(); uh1=myPort.read(); dl1=myPort.read(); dh1=myPort.read(); ul2=myPort.read(); uh2=myPort.read(); dl2=myPort.read(); dh2=myPort.read(); ul3=myPort.read(); uh3=myPort.read(); dl3=myPort.read(); dh3=myPort.read(); upvalue1=256*uh1 +ul1; downvalue1= 256*dh1+dl1; upvalue2=256*uh2 +ul2; downvalue2= 256*dh2+dl2; upvalue3=256*uh3 +ul3; downvalue3= 256*dh3+dl3; value1 = (upvalue1 + (1024-downvalue1))/2; value2 = (upvalue2 + (1024-downvalue2))/2; value3 = (upvalue3 + (1024-downvalue3))/2; filter1 = (1-eps) *filter1 + eps*value1; filter2 = (1-eps) *filter2 + eps*value2; filter3 = (1-eps) *filter3 + eps*value3; if(val==1 && val2==2 && val3==3 && val4==4){ if(filter1<500||filter2<500||filter3<500){ i+=60; fill(random(255),i,i/2,100-(i/10)); ellipse(250,250,100+(i/3),100+i/3); if(i>=255){ background(255); i=0; } } else{ background(255); i=0; fill(0); ellipse(250,250,100,100); } } /* println(val); println(val2); println(val3); println(val4); println(filter1); println(filter2); println(filter3); */ } fill(0); text(filter1, 100, 100); println(val); } /* // Wiring / Arduino Code // Code for sensing a switch status and writing the value to the serial port. int switchPin = 4; // Switch connected to pin 4 void setup() { pinMode(switchPin, INPUT); // Set pin 0 as an input Serial.begin(9600); // Start serial communication at 9600 bps } void loop() { if (digitalRead(switchPin) == HIGH) { // If switch is ON, Serial.print(1, BYTE); // send 1 to Processing } else { // If the switch is not ON, Serial.print(0, BYTE); // send 0 to Processing } delay(100); // Wait 100 milliseconds } */