import processing.serial.*; Serial myPort; // Create object from Serial class int pos[] = {0, 0}; float scale_factor = 1; int color_pick[] = {0, 0, 0}; float angle_rotation = 0; void setup() { size(500, 500); rectMode(CENTER); String portName = Serial.list()[4]; println(portName); myPort = new Serial(this, portName, 9600); myPort.clear(); myPort.bufferUntil('\n'); } void draw(){ if ( myPort.available() > 0) { byte myBytes[] = myPort.readBytesUntil('\n'); if (myBytes != null) { String tmp = new String(myBytes); int[] list = int(split(tmp, ',')); println(list[0]); println(list[1]); println(list[2]); println(list[3]); println(""); // read from the right joystick to move the rectangle up and down, left and right if (list[1] == 1023){ pos[0] -= 10; }else if(list[1] == 0){ pos[0] += 10; } if (list[0] == 1023){ pos[1] -= 10; }else if(list[0] == 0){ pos[1] += 10; } // read from the left joystick's up and down motions for the scale factor if (list[2] == 1023){ scale_factor = scale_factor*1.1; }else if(list[2] == 0){ scale_factor = scale_factor/1.1; } // read from the left joystick's left motions for color changing if (list[3] == 1023){ color_pick[0] = int(random(0,255)); color_pick[1] = int(random(0,255)); color_pick[2] = int(random(0,255)); } // read from the left joystick's right motions for rotating if (list[3] == 0){ angle_rotation = random(0,360); } } } background(255); // Set background to white fill(color_pick[0], color_pick[1], color_pick[2]); translate(width/2, height/2); rotate(angle_rotation); rect(pos[0], pos[1], scale_factor*10, scale_factor*10); }