Control P5 - Display numbers in Button labels

2.2k Views Asked by At

I am creating a number pad using Processing. I am using a tablet and the controlP5 library for the gui, then sending the value to an arduino. I'm having an issue naming my buttons with numbers. Here is my code to create Buttons:

n1=cp5.addButton("one",1)
.setPosition(470,390)
.setSize(100,100)
;

n2=cp5.addButton("two",2)
.setPosition(590,390)
.setSize(100,100)
;

...and some others.

I'd like to name my buttons with a number (to display numbers on my screen) but the names of the buttons are also the names of the functions used here to send the value associated with the button:

void one(int theValue) 
{ 
    buttonText= "OFF" ; 
    background(236, 240, 241); 
    sendLetter = "b" ;

    byte [] myByte = stringToBytesUTFCustom(sendLetter); 
    sendReceiveBT.write(myByte);
}

void two(int theValue) 
{ 
    buttonText= "OFF" ; 
    background(236, 240, 241); 
    sendLetter = "c" ;

    byte [] myByte = stringToBytesUTFCustom(sendLetter); 
    sendReceiveBT.write(myByte);
}

The problem is that I can't name my button "1", it doesn't work because controlP5 tries to find a method with the given name and link it to the controller, and methods cannot be named with a single digit. I have to name it "one" and it's a bit ugly for a number pad.

My question: is there a way to display a number without affecting the function used to send the value to the arduino?

1

There are 1 best solutions below

0
On BEST ANSWER

You can use setCaptionLabel(String) to set the visible label of the Button:

n1=cp5.addButton("one",1)
.setCaptionLabel("1")
.setPosition(470,390)
.setSize(100,100)
;

Taken from this discussion: http://processing.org/discourse/beta/num_1230541431.html#5