Connect a function to a button created in an object (ControlP5)

Interface i;
void setup() {
  size(800, 600);
  i = new Interface(this, "functionToTrigger");
}
void draw() {
  background(20);
}
void functionToTrigger() {
   println("Function triggered"); 
}

import controlP5.*;
class Interface {
  ControlP5 cp5;
  Interface(PApplet p_parent, String buttonTriggersThis) {
    cp5 = new ControlP5(p_parent);
    cp5.addButton(buttonTriggersthis)
    .setPosition(10, 10)
    .setSize(50,20);
  }
}

You could do this? I haven’t actually tried running this…

2 Likes