Unable to light up all the LEDS connected to Arduino using processing

I have 3 LEDs connected to my arduino which are controlled via laptop key presses with processing.

While the LEDs are able to light up when the respective buttons are pressed, i am unable to light up all 3 LEDs simultaneously when i press all 3 keys at the same time. I am however able to light up 2 LEDs by pressing 2 buttons simultaneously.

All the LEDs light up when their respective buttons are pressed, so i know that it is not a defective LED and/or faulty connections/wiring at play but something else that is causing the issue.

My processing code:

    import processing.serial.*;
    Serial myPort;
    
    void setup(){
      println("The available ports are: ");
      println(Serial.list());
      myPort = new Serial(this,Serial.list()[0],9600);
      myPort.buffer(64);
      size(500, 500);
    }
    
    void draw(){
      if(keyPressed){
        if(key == 'r' || key == 'R'){
          myPort.write(1);
          println("red");
        }
        else if(key == 'y' || key == 'Y'){
          myPort.write(2);
          println("yellow");
        }
        else if(key == 'g' || key == 'G'){
          myPort.write(3);
          println("green");
        }
      }
      
    }
    
    void keyReleased(){
     if(key == 'r' || key == 'R'){
          myPort.write(4);
          println("red released");
        }
        else if(key == 'y' || key == 'Y'){
          myPort.write(5);
          println("yellow released");
        }
        else if(key == 'g' || key == 'G'){
          myPort.write(6);
          println("green released");
        }
        
      println("released");
    }

My Arduino code:

    int red = 7;
    int yellow = 6;
    int green = 5;
    
    void setup(){
      Serial.begin(9600);
      pinMode(red,OUTPUT);
       pinMode(yellow,OUTPUT);
        pinMode(green,OUTPUT);
    }
    
    void loop(){
    
    }
    
    void serialEvent(){
        int input = Serial.read();
        if(input == 1){
          digitalWrite(red,HIGH);
        }
        else if(input == 2){
          digitalWrite(yellow,HIGH);
        }
        else if(input == 3){
          digitalWrite(green,HIGH);
        }
        else if(input == 4){
          digitalWrite(red,LOW);
        }
        else if(input == 5){
          digitalWrite(yellow,LOW);
        }
        else if(input == 6){
          digitalWrite(green,LOW);
        }
    }

Things i’ve tried.

  1. I’ve tried increasing the buffer size from 10(initially) to 64(in the code above)
  2. I’ve tried increasing the baud rate from 9600 to 12000, just in case it was the serial information not being read fast enough.

None of the things i’ve tried, listed above, was above to solve my problem, and i dont see what could be causing the problem.

Any advice would be much appreciated.

When you press three keys similtainousyl you do not get three ASCII characters generated in the key press function. You should see that by the fact that your Processing program never prints that out. Keyboards do a two key roll over function not a three key one. Therefore you will have to change your idea about how you want it to work.

Hello Mike,

Thanks for taking the time to reply, and +1 for a quick,concise answer that directly addresses my problem. I’ve googled 2 key rollovers, and the only solutions i can think of are assigning a keypress that lights up all 3 LEDs simultaneously, or using switches on my breadboard to light up the LEDs instead of keypresses on my keyboard.

Would you happen to have an alternative solutions?

PS.This is just me messing around with my Arduino, experimenting with controlling my Arduino via my computer

Would you happen to have an alternative solutions?

Well it is not really an Arduino problem, rather one on the computer. You might be able to do this if you can get at the low level hardware of the keyboard but I think nowadays they are all packaged up to look like USB devices. So I am not sure there is a problem.

All keyboards have key modifiers on them, like shift, command, alt, ctrl and so on. You could look into using these keys to detect multiple keys being held.