Having trouble hiding Controllers

I’ve been trying to have different knobs and buttons available depending on the tab pressed in the button bar at the top. Unfortunately, I haven’t been able to get this knob to hide using the button bar and am unsure as to why. Any help would be much appreciated! Thank you

import controlP5.*;

ControlP5 cp5;

ButtonBar bar;
Knob speedControl;

int speed;
PFont font;

void setup(){
size(1000, 1000);
smooth();
noStroke();

font = createFont(“Arial”, 32, true);

cp5 = new ControlP5(this);

speedControl = cp5.addKnob(“speedValue”)
.setRange(0,255)
.setValue(255)
.setPosition(150,150)
.setRadius(100)
.setNumberOfTickMarks(1)
.setTickMarkLength(8)
.snapToTickMarks(false)
.setColorForeground(color(100, 200, 50))
.setColorBackground(color(50, 80, 20))
.setColorActive(color(0,255,0))
.setDragDirection(Knob.HORIZONTAL)
.setCaptionLabel(“Speed Value”).setFont(font);

bar = cp5.addButtonBar(“bar”)
.setPosition(0, 0)
.setSize(1000, 50)
.addItems(split(“a b”," "))
.setColorForeground(color(100, 200, 50))
.setColorBackground(color(50, 80, 20))
.setColorActive(color(0,255,0))
.setCaptionLabel(“Speed Value”).setFont(font);
bar.changeItem(“a”,“text”,“Line Following”);
bar.changeItem(“b”,“text”,“Free Control”);
}

void draw(){
}

void speedValue(int speedValue){
speed = speedValue;
println("Motor Speed: " + speed);
}

void bar(int click) {
if(click == 0){
speedControl.hide();
}
if(click == 1){
println(“Free Control”);
speedControl.hide();
}
}

use this

cp5.hide (); /// to hide

cp5.show ();//// to show

chick your code

speedControl = cp5.addKnob("speedValue");

Hello,

Please format your code as a courtesy to the community:
https://discourse.processing.org/faq#format-your-code
You can go back and edit it.

I was able to hide\show the knob with these changes:

void draw() 
  {
  background(100);
  }

  if (click == 0) 
    {
    speedControl.hide();
    }
  
  if (click == 1) 
    {
    println("Free Control");
    speedControl.show();
    }
1 Like

@glv

nice to see you :smiley: :smiley: :smiley: :smiley:

1 Like