import processing.serial.*; Serial myPort; int val; float barWidth = 300.0; float sliderPos = 100.0; float hueVal = map(sliderPos, 0.0, barWidth, 0.0, 255.0); void setup() { String portName = Serial.list()[4]; myPort = new Serial(this, portName, 115200); size(400,100); background (128); colorMode(HSB, 255); stroke(0,0,0); println(hueVal); } void draw() { ////If you want to listen for something on the serial port, do this: //if (myPort.available()>0){ // val = myPort.readStringUntil('\n'); //} //println(val); background(128); fill (255); hueVal = drawSlider(20.0,20.0,barWidth,30.0,hueVal); val = 255 - (int)hueVal + 170; myPort.write(val); println(floor(hueVal)); } float drawSlider(float xPos, float yPos, float sWidth, float sHeight,float _hueVal){ fill(255); noStroke(); rect(xPos-5,yPos-10,sWidth+10,sHeight+20); //draw white background behind slider float sliderPos=map(_hueVal,0.0,255.0,0.0,sWidth); //find the current sliderPosition from hueVal for(int i=0;ixPos && mouseX<(xPos+sWidth) && mouseY>yPos && mouseY