Button Latch

Hi, I need to do a button latch circuit to put on a school project, but it is not working properly. The LED just keeps blinking kind of randomly and I don't know what to do anymore. What am I missing?

Just to give some context, the idea is to make one of these games where you need to pass a metal ring through a metal string without touching both. However, I'm doing it with a life system. The idea is that each time you press the button you add one life (1 led each, 3 max), and when you achieve the max you restart (1 led).

But first, just to learn how to do it, I was trying to do a simple button latch.

Please help me out, guys!

Jogo_Semana_da_Primavera.ino (390 Bytes)

Here it is.
Ignore that the led pin is wrong, I already corrected that.

you need debounce, some kind of delay(50) in your code

your led blinks randomly because , loop keeps moving fast enough to see you holding the button for a 'year'

LED blinks randomly because the input pin is floating when the button is not pressed, add a 10k resistor between input pin and GND.