Whack-A-LED game, only two out of three buttons work

Hi! I'm making a project of Whack-A-Mole with LED lights, three with one button each.

However, only two out of all three buttons work. I've checked if it's because of incorrect wiring and if it's something with the code, but I'm not getting anything. The third button just won't send the LOW value.

// "Whack-a-LED"

volatile byte power2 = HIGH;
volatile byte power1 = HIGH;
volatile byte power3 = HIGH;
int LED1 = 7;
int LED2 = 8;
int LED3 = 9;
int WhichLED = 0;

void setup() {
  pinMode(2, INPUT);
  pinMode(4, INPUT);
  pinMode(3, INPUT);
  pinMode(LED1, OUTPUT);
  pinMode(LED2, OUTPUT);
  pinMode(LED3, OUTPUT);
  digitalWrite(LED1, LOW);
  digitalWrite(LED2, LOW);
  digitalWrite(LED3, LOW);
  attachInterrupt(digitalPinToInterrupt(2), LED1off, FALLING);
  attachInterrupt(digitalPinToInterrupt(4), LED3off, FALLING);
  attachInterrupt(digitalPinToInterrupt(3), LED2off, FALLING);
}

void loop() {
  power1 = digitalRead(2);
  power2 = digitalRead(4);
  power3 = digitalRead(3);
  
  if (WhichLED == 7) {
    digitalWrite(LED1, HIGH);
  }
  
  if (!power1) {
      digitalWrite(LED1, LOW);
  }
  
  if (WhichLED == 8) {
    digitalWrite(LED2, HIGH);
  }
  
  if (!power2) {
      digitalWrite(LED2, LOW);
  }
  
  if (WhichLED == 9) {
    digitalWrite(LED3, HIGH);
  }
  
  if (!power3) {
      digitalWrite(LED3, LOW);
  }

  RandomLED();
}

void RandomLED() {
  delay(3000);
  WhichLED = random(7, 10);
}

void LED1off() {
  digitalWrite(LED1, LOW);
}
void LED2off() {
  digitalWrite(LED2, LOW);
}
void LED3off() {
  digitalWrite(LED3, LOW);
}

1st, the Uno only has 2 interrupt pins that can work on RISING or FALLING edges.
The rest of the IO pins can all be used for pin change interrupts.

Question I have is if this is a project built around learning interrupts (in which case it’s good to learn) but please don’t believe that you need interrupts to do this. Seriously, Arduino is 100’s of times faster than you need to just poll the buttons and get what appears to be instant response to any of them.

If you pinMode() your inputs as INPUT_PULLUP then you can wire your buttons to their pins and ground directly with no resistors to connect at all. When you source 5V to the INPUT moded pin you also need a pulldown resistor to ground between the button and the pin.

The Arduino chip has a built in 20K to 50K resistor for each IO pin that gets used when pinMode is INPUT_PULLUP. What it does is supply the pin with very weak current that can easily be grounded without burning up the pin or costing the chip much current (Uno can source/sink 200mA max).

When you read the pin, HIGH is pin not grounded (button up) and LOW is grounded (button down), which is the opposite of pin moded INPUT and fed 5V only when the button is down.

You use that massive delay so I won’t go into button bounce.

There’s a tutorial in the Arduino Playground that shows how to use leds as light sensors. It has a led that shines to match ambient light, works good within limits. The same principle could be used by your game if played with light falling on it (not in dim or dark lighting) by having the player cover the lit-up led with a finger. The led is also the button, can be mounted in a hole drilled through a not-thick board (like a cheap paint color sample ‘chip’ from Home Depot), recessed just enough so the led doesn’t get touched but can be seen.

https://playground.arduino.cc/Learning/LEDSensor

As to your code, first off you wrote it and it runs is very good. It can serve as a learning platform when you pick up some new info to try out. Oh, here’s one now!

https://www.arduino.cc/en/Reference/SwitchCase

Thanks, also I did this for a task at high school. I solved it by removing the third button, then setting it up to turn LED 3 off by holding both buttons in Pins 2 and 3.

Look up pin change interrupt if you want to put the 3rd button back as interrupt.

A lot of the better automation techniques use the "Many Things At Once" approach to coding where delay is a dirty word.
You learn and practice that, it's a way that can take you far as a hobbyist or engineer.
Actually, you would want it for making leds that are also buttons in practical apps.

The best part for you is that you're young and have lots to learn and lots of time to learn. Compare to having lots to learn and little time to do it! Person in the latter situation might wish they had been better prepared.

I graduated HS class of 75. My time is running out so I share all I can.