Atmega328p: why button input is read as 0 when pressed?
What PINB &amp; (1&lt;&lt;7) will return depend on how the button is wired. It will return true (not 0) value if the voltage on the pin is in the range of the high logic level and false (0) if it is in the range of the low logic level.

In the first case, the GPIO pin is pulled up to VCC (logic high) by default, so if the button is not pressed PINB &amp; (1&lt;&lt;7) will return true. If you press the button, the voltage at the pin will be GND (logic low), so your statement will return false (0).

In the second case the configuration is reversed. The pin is pulled down to GND by default and when the button is pressed the voltage will be VCC. So the input will be true on button presses.







simulate this circuit &ndash; Schematic created using CircuitLab

On your board, you probably have the first case.