I am using Processing IDE with Java language.
There are serial port writings for lighting some LEDs and my aim was;
send the c (Color) from cp (colorpicker) to the corresponding LEDs. Since I have too many LED areas, I used a for loop instead of writing too many functions like void AREA1 etc. So the port writing part of my code is:
public void controlEvent1(ControlEvent c) {    
  if (c.isFrom(cp)) {
    r = int(c.getArrayValue(0));
    g = int(c.getArrayValue(1));
    b = int(c.getArrayValue(2));
  } 
}
public void controlEvent2(CallbackEvent event) {
  
  String s1 = "abcdt";
  
  if (event.getAction() == ControlP5.ACTION_CLICK) {
      final String controlName = event.getController().getName(); 
              
      /*
      Ring Areas
      */              
      
      //Ring1 Areas
       for (int i = 0; i < s1.length(); i++) {
          if (controlName.equals("Ring1AREA" + str(i +1))){
              println("RING1AREA" + (i+1) + " is Pressed");
              if (port != null) port.write(s1.charAt(i) + "\n");}}                              
              
  }
}
Firstly:
- controlEvent1 is working fine alone.
 - controlEvent2 is working fine always.
 
My problem is, whenever I enable both the controlEvents together, the controlEvent1 is not working. I mean, it works only when I delete the controlEvent2 part and I could not figure how to fix it.
I thought the reason could be about using a mouseclick condition in the colorpicker, so in the controlevent1; and then using ACTION_CLICK on the controlevent2. Would they conflict in this case? :
void mousePressed() {
  if( mouseX > 40 && mouseX <240 && mouseY>360 && mouseY<560){
  if(port == null){
    println("no serial, ignoring");
    return;
  }
  String sendColor = nf(r_, 3) + "," + nf(g_, 3) + "," + nf(b_, 3) + '\n';
  println("sending to Arduino:", sendColor);
  
  port.write(sendColor);
  }
}