Why does this switch go both to ground AND to the input pin?
This is the typical way to connect a switch to digital logic. There is a pulldown resistor, which has one terminal connected to ground and the other end connected to the switch. The other terminal of the switch is connected to the power supply voltage (usually called Vdd).
Consider the point where the switch and resistor are connected. If the switch is open then the voltage at this point will be essentially 0, because of the connection through the resistor. If the switch is closed then current flows through the switch and through the resistor. This makes the voltage across the resistor increase until it is essentially equal to Vdd.
Now we connect our logic input at that point, where the resistor and switch are connected to each other. When the switch is open our logic input sees a very low voltage and when the switch is closed our logic sees a voltage close to the power supply voltage. An open switch is a logic zero, a closed switch is a logic one.
The resistor is necessary because without it the logic input would be &quot;floating&quot;...it wouldn't have a conductive path to either ground or the power supply. A floating logic input picks up noise from the environment and its logic level bounces all over the place. The resistor ensures that we get a valid, stable low voltage when the switch is open.