I want the listed buttons to work only one at a time

Hello, I am a student who is making a control program using Processing 4.
The control program has 128 listed buttons, and when a button is pressed, the pin connected to the corresponding button in the driving circuit turns on. Currently, there is a program, but I am trying to modify it so that only one button out of 128 is On. (Currently, all buttons can be turned on, if another button is pressed while one is turned on, only the newly pressed button needs to be turned on)
I’m not sure how to fix it, so I’m asking. Thank you for your reply.
here is a code under the line

void gui_setup(){
cp5 = new ControlP5(this);

  electrodeBox = cp5.addCheckBox("electrodeBox")
    .setPosition(electrode_checkbox_x, electrode_checkbox_y)
    .setSize(electrode_checkbox_width, electrode_checkbox_height)
    .setItemsPerRow(16)
    .setSpacingColumn(0)
    .setSpacingRow(0)
    .setImages(electrode_unclick, electrode_unclick, electrode_click);

  for (int j=0; j<16; j++)
  {
    for (int i=0; i<8; i++)
    {
      electrodeBox.addItem(char(j+'A')+str(i+1), i+j*8);
    }
  }
}
void electrodeBox(float[] float_electrode)
{
  boolean[x] electrode=new boolean[128];
  for (int i=0; i<128; i++)
  {
    if (float_electrode[i]==0.0)electrode[i]=false;
    else electrode[i]=true;
  }
  hvout_setting(electrode_to_hvout(electrode));
}
1 Like

1 Like

this is my program image

1 Like

please post a runable version of your code

I think what you are looking for is called a ‘radio group’. The following code was taken from the ControlP5 Examples (ControlP5group):

import controlP5.*;

ControlP5 cp5;

void setup() {
  size(800, 400);
  cp5 = new ControlP5(this);
  cp5.addRadioButton("radio")
    .setPosition(100, 30)
    .setSize(40, 30)
    .addItem("black", 0)
    .addItem("red", 1)
    .addItem("green", 2)
    .addItem("blue", 3)
    .addItem("grey", 4)
    ;
}

void draw() {
  background(0);
}

void controlEvent(ControlEvent theEvent) {
  if (theEvent.isGroup()) {
    println("got an event from group "
      +theEvent.getGroup().getName()
      +", isOpen? "+theEvent.getGroup().isOpen()
      );
  }
}

Modified to add a grid of buttons:

import controlP5.*;

ControlP5 cp5;
RadioButton radio;

final int _numCols = 16;
final int _numRows = 8;

void setup() {
  size(750, 350);
  background(209);
  cp5 = new ControlP5(this);
  radio =  cp5.addRadioButton("radio");
  for (int x = 0; x < _numCols*_numRows; x++) {
    radio.setItemsPerRow(_numCols);
    radio.setPosition(30, 30);
    radio.setSize(40, 30);
    radio.addItem(str(x), x);
  }
}

void draw() {
}

void radio(int a) {
  println("radio id: ", a);
}

void controlEvent(ControlEvent theEvent) {
  if (theEvent.isGroup()) {
    println("event from group "
      +theEvent.getGroup().getName()
      +", isOpen? = "+theEvent.getGroup().isOpen()
      );
  }
}
2 Likes

The original code is too long, so I used only the necessary parts, so it doesn’t seem to work properly. Sorry.

1 Like

thank you for the reply
I was able to edit it using Radiobutton.
Additionally, I am trying to modify it so that multiple selections can be made when pressing the SHIFT key, void keyPressed(){
} How should I define it inside the function??

continued in new thread

1 Like