// Fabacademy 2020 || St. Jude FabLab import processing.serial.*; // import the Serial communication library Serial myPort; // This is the serial port you will use for communication // rectangle 1 parameters and variables int rect1X, rect1Y; // Position of rectangular button int rect1Size; // Size of rectangle color rect1Color; // Rectangle color boolean // rectangle 2 parameters and variables int rect2x, rect2Y;// Position of rectangular button int rect2Size; // Size of rectangle color rect2Color; // Rectangle color boolean // rectangle 3 parameters and variables int rect3X, rect3Y; // Position of rectangular button int rect3Size; // Size of rectangle 3 color rect3Color; // Rectangle color boolean void setup() { printArray(Serial.list()); // print the list of serial ports available myPort = new Serial(this, Serial.list()[0], 9600); //create the port according to the list size(700,300); // window size background(255,255,255); // window background color (white) // button 1 definition rect1Color = color(0,0,255); //fill color for button1 (r,g,b) rect1X = 100; // position X for button 1 rect1Y = 100; // position Y for button 1 rect1Size = 100; // side size for button 1 // button 2 definition rect2Color = color(43,194,55); rect2x= 250; // POSITION x for button 2 rect2Y= 100; // position Y for button 2 rect2Size= 100; // side size for button 2 // button 3 definition rect3Color = color(185,17,17); rect3X= 400; // POSITION x for button 3 rect3Y= 100; // position Y for button 3 rect3Size= 100; // side size for button 3 } void draw() { stroke(0,0,0); // color for button 1 edge (black) fill(rect1Color); // color for button 1 fill (blue) rect(rect1X, rect1Y, rect1Size, rect1Size); // command for drawing button 1 stroke(0,0,0); // color for button 2 edge (black) fill(rect2Color); // color for button 1 fill (blue) rect(rect2x, rect2Y, rect2Size, rect2Size); // command for drawing button 1 stroke(0,0,0); // color for button 3 edge (black) fill(rect3Color); // color for button 1 fill (blue) rect(rect3X, rect3Y, rect3Size, rect3Size); // command for drawing button 1 } void mouseReleased() // this is a function that executes when a mouse button is released { // when the mouse button is released, we ask what was the position of the mouse pointer if (mouseX >= rect1X && mouseX <= rect1X + rect1Size && mouseY >= rect1Y && mouseY <= rect1Y + rect1Size) { // if the mouse pointer was inside the button 1 coordinates this is executed println("turn on blue led"); //print on Processing console myPort.write("1"); // send 1 over serial } { // when the mouse button is released, we ask what was the position of the mouse pointer if (mouseX >= rect2x && mouseX <= rect2x + rect2Size && mouseY >= rect2Y && mouseY <= rect2Y + rect2Size) { // if the mouse pointer was inside the button 2 coordinates this is executed println("turn on green led"); //print on Processing console myPort.write("2"); // send 2 over serial } { // when the mouse button is released, we ask what was the position of the mouse pointer if (mouseX >= rect3X && mouseX <= rect3X + rect3Size && mouseY >= rect3Y && mouseY <= rect3Y + rect3Size) { // if the mouse pointer was inside the button 2 coordinates this is executed println("turn on red led"); //print on Processing console myPort.write("3"); // send 2 over serial } } } }