Closed Sastas closed 3 years ago
A pullup resistor for the button is required. Without it, the pin picks up stray fields which create spurious input.
Change pinMode(BUTTON1_PIN, INPUT)
to pinMode(BUTTON1_PIN, INPUT_PULLUP)
and the problem goes away. However, calling pinMode()
for a Button object is redundant as the call to Button::begin()
sets the proper pin mode, so I do not recommend it.
I found that if I use in the setup area to set up my inputs also, not just my outputs, the code start to act weird, first it is put my led on, then sometimes its start blinking or just dont do anything. Just modified one of the examples to visualize: