D9 looks like it is a "floating input" when the 5V is not connected to it. That means the input state is undefined.
Your senior won't be very impressed with that. You need a resistor from D9 to ground, about 10k for example.
Also hope that your senior doesn't know that you need current limiting resistors on a LED display.
The really interesting part will be when you connect D9 to a 12V signal and blow up the Arduino...
It's pointless to discuss code until those issues are resolved.