import processing.serial.*; Serial myPort; // Create object from Serial class int val; // Data received from the serial port void setup() { size(800, 800); //size of a graphic window in pixle String portName = Serial.list()[2]; //"COM5"; println(Serial.list()); //debuging to show port myPort = new Serial(this, portName, 9600); } void draw() { background(255); if (mouseOverCircle1_L() == true) { // If mouse is over square, fill(0,0,255); // change color and myPort.write('H'); // send an H to indicate mouse is over square ellipse(width/4, height/2, 200, 200); // Draw Circle in the center } else { // If mouse is not over square, fill(0); // change color and ellipse(width/4, height/2, 200, 200); // Draw Circle in the center } if (mouseOverCircle1_R() == true) { // If mouse is over square, fill(255,0,0); // change color and myPort.write('L'); // send an H to indicate mouse is over square ellipse(width/4*3, height/2, 200, 200); // Draw Circle in the center } else { // If mouse is not over square, fill(0); // change color and ellipse(width/4*3, height/2, 200, 200); // Draw Circle in the center } } boolean mouseOverCircle1_L() { // Calculate distance from mouse to circle center float d = dist(mouseX, mouseY, width/4, height/2); // If the distance is less than the circle's radius, mouse is over it return d < 100; // Radius of the circle is 100 (diameter is 200) } boolean mouseOverCircle1_R() { // Calculate distance from mouse to circle center float d = dist(mouseX, mouseY, width/4*3, height/2); // If the distance is less than the circle's radius, mouse is over it return d < 100; // Radius of the circle is 100 (diameter is 200) }