Alright, I am building a new virtual contol panel for Walter using the controlP5 system of buttons and sliders etc. I have taken the example code for each of the contols I would like to use, cleaned them up and converted their final output to an int so it is all happy-slappy and ready to be sent via serial UART. Each of my controls work stand-alone and work great. Now I have to start putting them all together...
These controls do not have to be "watched" within void draw, instead when they are used, they get caught and read by "controlEvent". Each of the example codes use basically the same controlEvent routine so when you start putting these controls together, a way to distinguish which control what moved or adjusted is needed. There is a controlEvent example, which I have poured over and thought that I had followed exactly but I still come up with errors. Not to mention, I am still learning/figuring out what is what in terms of variable names, functions, classes etc. I mean, c'mon when all variables can be named whatever you want, it is sometimes hard to figure out what is a keyword and what is a name someone made up (yes, I know a lot of stuff is color coded but it's still tough).
Currently, I am working with the control event example and also the radiobutton example (I just picked the radiobutton code at random for this testing and experimentation). The radiobutton code looks like this:
/**
* ControlP5 RadioButton
* by andreas schlegel, 2009
*/
import controlP5.*;
ControlP5 controlP5;
int myColorBackground = color(0,0,0);
public RadioButton r;
void setup() {
size(400,400);
smooth();
controlP5 = new ControlP5(this);
r = controlP5.addRadioButton("radioButton",20,160);
r.setColorForeground(color(120));
r.setColorActive(color(255));
r.setColorLabel(color(255));
r.setItemsPerRow(5);
r.setSpacingColumn(50);
addToRadioButton(r,"Auto",1);
addToRadioButton(r,"RC",2);
addToRadioButton(r,"TBD",3);
addToRadioButton(r,"TBD",4);
addToRadioButton(r,"TBD",5);
}
void addToRadioButton(RadioButton theRadioButton, String theName, int theValue ) {
Toggle t = theRadioButton.addItem(theName,theValue);
t.captionLabel().setColorBackground(color(80));
t.captionLabel().style().movePadding(2,0,-1,2);
t.captionLabel().style().moveMargin(-2,0,0,-3);
t.captionLabel().style().backgroundWidth = 46;
}
void draw() {
background(myColorBackground);
}
void controlEvent(ControlEvent theEvent) {
print("got an event from "+theEvent.group().name()+"\t");
for(int i=0;i<theEvent.group().arrayValue().length;i++) {
print(int(theEvent.group().arrayValue()[i]));
}
println("\t "+theEvent.group().value());
myColorBackground = color(int(theEvent.group().value()*50),0,0);
}
Now, it seems that the first thing to do is to set an id for a new button when it is created. In addition, it also seems that it must be declared as "public" although I am a little confused here as well. In terms of the identification, it seemed pretty straight-forward according to the example. .setId() is simply added to the "add button" command. If I were to do this to the above code, it would look like this:
r = controlP5.addRadioButton("radioButton",20,160).setId(1);
However, when I do this, I get this error: cannot convert from void to RadioButton. This leads me to think I am missing something very simple --or-- I am missing the big picture of the whole system and I should just slit my wrists and end it now. Either way, I am open to your thoughts.