Getting ControlP5 Button isOn()
in
Contributed Library Questions
•
1 year ago
I can't seem to figure out how to get the status of a Button that is set as a switch. Line 47 gives me a function (isOn) doesn't exist error. I know it has something to do with the fact that the function is on the Button and not the Controller but I can't seem to figure out the syntax to access the isOn(). I was using Toggle instead of Button, and using getValue(), which was returning 0 or 1. In this example if I use getValue() I always get 0.0. Toggle works but I didn't like the image rollover behavior.
- import controlP5.*;
- ControlP5 cp5;
- int myColor = color(255);
- int c1,c2;
- float n,n1;
- void setup() {
- size(400,400);
- noStroke();
- PImage[] imgs = {loadImage("button_a.png"),loadImage("button_b.png"),loadImage("button_c.png")};
- cp5 = new ControlP5(this);
- // create a new button with name 'buttonA'
- cp5.addButton("colorA")
- .setValue(0)
- .setSwitch(true)
- .setPosition(100,100)
- .setImages(imgs)
- .updateSize()
- .setId(1);
- ;
- }
- void draw() {
- background(myColor);
- myColor = lerpColor(c1,c2,n);
- n += (1-n)* 0.1;
- }
- public void controlEvent(ControlEvent theEvent) {
- println(theEvent.getController().getName());
- n = 0;
- switch(theEvent.getController().getId()) {
- case(1):
- // do something
- //if (cp5.controller("ColorA").isOn()) {
- // do something
- //}
- break;
- }
- }
1