title: How can I detect the press of three switches by an interrupt service routine connected to just one interrupt pin
body: <p>Lately, I tried to use my Arduino Uno (AtMega328) board to detect the press of a series of three switches by an interrupt service routine.</p>
  
  <p>If have three switches for called R, G and B. Whenever,at least one of these switches is pressed once a RGB-Led should toggle its state for red, green or blue. </p>
  
  <p>Now, it was no problem for just two switches R and G, as the Arduino Uno board has two interrupt <a href="https://www.arduino.cc/reference/en/language/functions/external-interrupts/attachinterrupt/" rel="nofollow noreferrer">capable pins (2 and 3)</a>. </p>
  
  <p>But, for the switch B I'm lacking another interrupt pin to detect the press of at least one of the three switches.</p>
  
  <p>Is there a possible circuit, that easily allows one to detect the press of at least one of the three switches, so that I can just use one interrupt capable pin to detect the press of any switch?</p>
  
  <p>The code for two leds using the Arduino IDE was super easy for just two switches:</p>
  
  <pre><code>const int buttonRed = 2;     // the number of the pushbutton pin
  const int ledRed =  13;      // the number of the LED pin
  
  const int buttonGreen= 3;
  const int ledGreen=12;
  
  // variables will change due to ISR
  volatile int redState = 0;         
  volatile int greenState=0;
  
  void setup() {
    // initialize the LED pin as an output:
    pinMode(ledRed, OUTPUT);
    // initialize the pushbutton pin as an input:
    pinMode(buttonRed, INPUT);
  
    pinMode(ledGreen, OUTPUT);
    pinMode(buttonGreen, INPUT);
  
    // Attach an interrupt to the ISR vector
    attachInterrupt(digitalPinToInterrupt(buttonRed), redButton_ISR, CHANGE); 
    attachInterrupt(digitalPinToInterrupt(buttonGreen), greenButton_ISR, CHANGE); 
  }
  
  void loop() {
    // Nothing to do here
  }
  
  void greenButton_ISR() {
    greenState=digitalRead(buttonGreen);
    digitalWrite(ledGreen, greenState);
  }
  
  void redButton_ISR() {
    redState = digitalRead(buttonRed);
    digitalWrite(ledRed, redState);
  } 
  </code></pre>