Sending a Midi Note

When you have a switch wired to an input up you need to have a definite electrical signal for both when it is off and when it is on. When you switch the switch on, you are connecting it to 5V and your get a HIGH in the code. If you simply disconnect the switch and do not pull it down to 0V with through a resistor, then you get a floating input that can flip all over the place. Look up the principle for the "pull down" resistor circuit either on this forum or using google.

The same applies for a circuit that is normally at 5V and is switched to low. In this case the resistor is called a pull-up resistor, but the reasoning behind it is the same.