import processing.serial.*; float c; int colour_rgb, colour_r, colour_g, colour_b, spos=90; Serial port; PImage img; void setup(){ // img = loadImage("colour-wood.jpg"); img = loadImage("RGB-wheel.jpg"); size(((img.width)/2), ((img.height)/2)); rectMode(RADIUS); // println(Serial.list()); port = new Serial(this, Serial.list()[4], 19200); } // calculate servo postion from mouseX and send to serial port void update(int x) { //Calculate servo postion from mouseX spos= 360*x/(180-(img.width)); //println(spos); //write servo position ( from 0 to 180) to serial port with byte id at beginning (S) and dud value (L) port.write("SL"); port.write(spos); } void draw(){ //draw image image(img, 0, 0, ((img.width)/2), ((img.height)/2)); //get rgb colour values where mouse pointer is color c = get(mouseX, mouseY); fill(c); stroke(255); // assign rgb values into individual variables colour_r = int(red(c)); colour_g = int(green(c)); colour_b = int(blue(c)); //call update function to find servo position based on x position of mouse pointer update(mouseX); //write rgb variables to serial port with byte id at beginning (C) and dud value (L) port.write("CL"); port.write(colour_r); port.write(colour_g); port.write(colour_b); // println(colour_r); // println(colour_g); // println(colour_b); rect(mouseX, mouseY, 10, 10); }