ControlP5 contol toggles

please format code with </> button * homework policy * asking questions

I’m trying to make a panel of toggles that can be affected/changed by buttons, like setting multiple toggles’ state from false to true using one button, while still being able to use individual toggles.

Here is how I am making each toggle:

    .setPosition(100, 100)  
    .setSize(200, 200)    

Here is how I am checking each toggle:

void one(boolean theFlag){
  if (theFlag == true)
  if (theFlag == false)

I want to be able to change the state of several toggles with one button, not just setting it to a default state.

When I try cp5.getController("one").setValue(cp5.getController("one").getDefaultValue()); I can set each toggle to false, as this is the default state, but when I try `cp5.getController(“one”).setValue(true)’ it says it won’t take a boolean, despite the default value returning a boolean.

How do I change these toggles “remotely?”

Hi @PaladinBobcat ,

Welcome to the forum! :slight_smile:

So, if I understood correctly, the following code is what you are trying to achieve.
So you can toggle the toggle buttons individually and when you click on the setter button, it sets all the toggle buttons to true state!

import controlP5.*;

ControlP5 cp5;
Toggle togglers[];
Button button;

int col = color(255);

boolean toggleValue = false;

void setup() {
  size(400, 400);

  cp5 = new ControlP5(this);

  togglers = new Toggle[3];
  // create a toggle and change the default look to a (on/off) switch look
  togglers[0] = cp5.addToggle("toggle1")
    .setPosition(40, 100)
    .setSize(50, 20)
  togglers[1] = cp5.addToggle("toggle2")
    .setPosition(40, 200)
    .setSize(50, 20)
  togglers[2] = cp5.addToggle("toggle3")
    .setPosition(40, 300)
    .setSize(50, 20)

  button = cp5.addButton("setter")
    .setPosition(300, 200)
    .setSize(50, 19)

void draw() {

void mousePressed() {
  if (button.isPressed()) {
    for (int i = 0; i < 3; i++) {

Hope it helps guide you!

1 Like