import processing.serial.*; Serial myPort; // The serial port: int backValue = 255; // Declare variable 'backValue' and assign it the value 255 void setup() { // The setup() function is run once, when the program starts. It's used to define initial enviroment properties. size(640, 360); background(backValue); printArray(Serial.list()); // List all the available serial ports: myPort = new Serial(this, "COM5", 9600); // Open the port you are using at the rate you want: } void draw() { // Called directly after setup(), the draw() function continuously executes the lines of code contained inside its block until the program is stopped or noLoop() is called. } void mousePressed() { //The mousePressed() function is called once after every time a mouse button is pressed. if (backValue == 255) { //If the test evaluates to true, the statements enclosed within the block are executed backValue = 10; myPort.write(0); //low } else { //It specifies a block of code to execute when the expression in if is false. backValue = 255; myPort.write(1); //high } background(backValue); }