I've got the following Processing code using controlP5 modules:
import controlP5.*;
ControlP5 cp5;
void setup() {
size(180,240);
smooth();
noStroke();
cp5 = new ControlP5(this);
cp5.addSlider("CCV_Control")
.setPosition(40,40)
.setNumberOfTickMarks(11)
.setSliderMode(Slider.FLEXIBLE)
.showTickMarks(false)
.snapToTickMarks(true)
.setSize(100,20)
.setRange(0,100)
.setValue(20)
.setLabel("CCV Percent Open");
cp5.getController("CCV_Control").getCaptionLabel().align(ControlP5.CENTER, ControlP5.BOTTOM_OUTSIDE).setPaddingY(2);
cp5.addKnob("Water_Flow")
.setRange(0,70)
.setValue(20)
.setPosition(40,100)
.setRadius(50)
.setNumberOfTickMarks(28)
.snapToTickMarks(true)
.setLabel("Facility Water");
}
void draw() {
fill(140);
rect(20,20,140,200);
}
void Water_Flow(int theValue) {
float ccvPercentage = 0;
if (theValue <= 2) {
cp5.getController("Water_Flow").setColorBackground(color(200, 0, 0));
cp5.getController("CCV_Control").setValue(0);
} else {
cp5.getController("Water_Flow").setColorBackground(color(0, 31, 63));
ccvPercentage = (theValue*110)/70;
cp5.getController("CCV_Control").setValue(ccvPercentage);
}
}
void CCV_Control(int theValue) {
float facilityWaterFlow = 0;
if (theValue <= 2) {
//cp5.getController("Water_Flow").setValue(0);
} else {
facilityWaterFlow = (theValue*70)/100;
//cp5.getController("Water_Flow").setValue(facilityWaterFlow);
}
println("Water Flow: "+facilityWaterFlow+ " is CCV percent: "+theValue);
}
It works fine, but I need these two control to be tied to each other in both directions. But when I uncomment the 'getController("Water_Flow")' lines the logs are flooded with errors. Is there an easier way to tie them together?
Here's the updated code based on apodidae's response: