# ControlP5 contol toggles

**URL:** <https://discourse.processing.org/t/controlp5-contol-toggles/32514>\
**Category:** Libraries\
**Created:** [September 29, 2021, 6:01pm UTC](https://discourse.processing.org/t/controlp5-contol-toggles/32514 "2021-09-29T18:01:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![PaladinBobcat](https://avatars.discourse-cdn.com/v4/letter/p/9d8465/32.png) [@PaladinBobcat](https://discourse.processing.org/u/PaladinBobcat)\
**Post date:** [September 29, 2021, 6:01pm UTC](https://discourse.processing.org/t/controlp5-contol-toggles/32514/1 "2021-09-29T18:01:02Z")

</div>

> please format code with \</\> button \* [homework policy](https://discourse.processing.org/faq/#homework) \* [asking questions](https://discourse.processing.org/t/2147)

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:

```auto
cp5.addToggle("one")    
    .setPosition(100, 100)  
    .setSize(200, 200)    
    .setFont(font)
    .setValue(false)
    .setColorBackground(selectColor)
    .setColorForeground(basicColor)
    .setColorActive(toggleColor);

```

Here is how I am checking each toggle:

```auto
void one(boolean theFlag){
  if (theFlag == true)
  {
    port.write('A');
  }
  
  if (theFlag == false)
  {
    port.write('a');
  }
}

```

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?”

---

<div class="post-metadata">

**Author:** ![MiguelSanches](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/miguelsanches/32/11172_2.png) [@MiguelSanches](https://discourse.processing.org/u/MiguelSanches)\
**Post date:** [September 30, 2021, 8:48am UTC](https://discourse.processing.org/t/controlp5-contol-toggles/32514/2 "2021-09-30T08:48:51Z")

</div>

Hi @PaladinBobcat ,

Welcome to the forum! 🙂

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!

```auto
import controlP5.*;

ControlP5 cp5;
Toggle togglers[];
Button button;

int col = color(255);

boolean toggleValue = false;

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

  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)
    .setValue(true)
    .setMode(ControlP5.SWITCH)
    ;
  togglers[1] = cp5.addToggle("toggle2")
    .setPosition(40, 200)
    .setSize(50, 20)
    .setValue(true)
    .setMode(ControlP5.SWITCH)
    ;
  togglers[2] = cp5.addToggle("toggle3")
    .setPosition(40, 300)
    .setSize(50, 20)
    .setValue(true)
    .setMode(ControlP5.SWITCH)
    ;

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

void draw() {
  background(0);
}

void mousePressed() {
  if (button.isPressed()) {
    for (int i = 0; i < 3; i++) {
      togglers[i].setValue(true);
    }
  }
}

```

Hope it helps guide you!
