import processing.serial.*; float redValue = 0; // red value float greenValue = 0; // green value float blueValue = 0; // blue value float potValue = 0; Serial myPort; void setup() { size(1500, 1000); noStroke(); myPort = new Serial(this, Serial.list()[1], 9600); // don't generate a serialEvent() unless you get a newline character: myPort.bufferUntil('\n'); } void draw() { background(0); //fill(redValue, blueValue, greenValue); noStroke(); smooth(); fill(redValue, greenValue, blueValue); ellipse(random(100, 200), random(100, 200)+greenValue, 200, 200+greenValue); fill(greenValue, redValue, blueValue); rect(random(200,800), random(100, 600)+blueValue, random(100, 300)+greenValue, random(100, 200)+redValue); fill(blueValue, greenValue, redValue); triangle (random(300, 700), random(100, 800), 50+greenValue, 100+blueValue, 50, 300); // fill(potValue, redValue, blueValue); //ellipse(200+potValue,300+redValue, 30+potValue, 30+potValue); } void serialEvent(Serial myPort) { // get the ASCII string: String inString = myPort.readStringUntil('\n'); if (inString != null) { // trim off any whitespace: inString = trim(inString); // split the string on the commas and convert the // resulting substrings into an integer array: float[] colors = float(split(inString, ",")); // if the array has at least three elements, you know // you got the whole thing. Put the numbers in the // color variables: if (colors.length >=3) { // map them to the range 0-255: redValue = map(colors[0], 0, 1023, 0, 255); greenValue = map(colors[1], 0, 1023, 0, 255); blueValue = map(colors[2], 0, 1023, 0, 255); //potValue = map(colors[3], 0, 1023, 0, 255); } } }