you might look into
PDE / File / Examples / Contriburted Libraries / Control P5 / controllers / ControlP5buttonBar
or make your own array of buttons:
/* ControlP5 Button */
import controlP5.*;
ControlP5 cp5;
Button[] btns = new Button[5];
void setup() {
size(400, 600);
cp5 = new ControlP5(this);
for ( int i = 0; i < 5; i++ ) {
btns[i] = cp5.addButton( "click"+str(i) )
.setValue(i)
.setPosition(100, 20+30*i)
.setSize(200, 19) ;
}
}
void draw() {
background(200, 200, 0);
}
public void controlEvent(ControlEvent theEvent) {
println(theEvent.getController().getName());
}
public void click0(int theValue) {
println("a button event from click0: "+theValue);
}
a auto GRID version:
/* ControlP5 Button GRID */
import controlP5.*;
int xg = 10, yg = xg, wg = 70, hg = wg, offg =5, grid = 5, many = grid*grid; // GRID DESIGN
ControlP5 cp5;
Button[] btns = new Button[many];
void setup() {
size(400, 400);
cp5 = new ControlP5(this);
for ( int i = 0; i < many; i++ ) {
int bx = xg+(i%grid)*( wg+offg);
int by = yg+(floor(i/grid))*(hg+offg);
btns[i] = cp5.addButton( "click"+str(i) )
.setValue(i)
.setPosition(bx,by)
.setSize(wg,hg) ;
}
}
void draw() {
background(200, 200, 0);
}
public void controlEvent(ControlEvent theEvent) {
println(theEvent.getController().getName());
}
public void click0(int theValue) {
println("a button event from click0: "+theValue);
}
for TOGGLE might also look into
PDE / File / Examples / Contriburted Libraries / Control P5 / controllers / ControlP5toggle
still can use Button like
/* ControlP5 Button GRID / TOGGLE type*/
import controlP5.*;
ControlP5 cp5;
int xg = 10, yg = xg, wg = 70, hg = wg, offg =5, grid = 5, many = grid*grid; // GRID DESIGN
Button[] btns = new Button[many];
void setup() {
size(400, 400);
cp5 = new ControlP5(this);
for ( int i = 0; i < many; i++ ) {
int bx = xg+(i%grid)*( wg+offg);
int by = yg+(floor(i/grid))*(hg+offg);
btns[i] = cp5.addButton( "click_"+str(i) )
.setSwitch(true)
//.setOff()
.setColorForeground(color(200, 0, 200)) // mouse over
.setColorActive(color(0, 200, 0)) // clicked ON
.setId(i)
.setPosition(bx, by)
.setSize(wg, hg) ;
}
}
void draw() {
background(200, 200, 0);
}
public void controlEvent(ControlEvent theEvent) {
String name = theEvent.getController().getName();
int btn = theEvent.getController().getId();
println(name , btn , btns[btn].isOn() );
}
void keyPressed() {
if ( key == 'a' ) printAll();
}
void printAll() {
println("print btns if ON ");
for ( int i = 0; i < many; i++ ) if ( btns[i].isOn() ) println(i, btns[i].isOn() );
}