//from Daily Duino example: http://dailyduino.com/archives/483 //Check if the mouse is over a rectangle and write the status to the serial port import processing.serial.*; Serial port; //Create object from Serial class void setup() { size(200, 200); noStroke(); frameRate(30); //Open the port that the board is connected to and use the same speed (9600bps) port = new Serial(this, Serial.list()[0], 9600); } void draw() { background (255); if (mouseOverRect() == true) { //If mouse if over square fill(242, 204, 47); //change color port.write('H'); //send H to serial port } else { //If mouse is NOT over square fill(0); //change color port.write('L'); //send L to serial port } rect(50, 50, 100, 100); //Draws the square } boolean mouseOverRect() { //Tests if mouse is over square return ((mouseX >= 50) && (mouseX <= 150) && (mouseY >= 50) && (mouseY <= 150)); }