Hi, I'm having a problem with a project that I'm working on.
I need the arduino to see how many times I push a button inside a time frame.
Lets give an example:
if I press the push button once inside a 2 seconds time frame, it will turn on an LED, and it will stay on for 10 seconds.
but if I press it twice inside a 2 seconds frame, it will turn the LED off at any point.
The LED has to turn on only after those 2 seconds passed.
if I press the push button once inside a 2 seconds time frame, it will turn on an LED,
Huh? One press within two seconds? Two seconds starting when? Do you see the flaw in your description?
and it will stay on for 10 seconds.
Okay, fine.
but if I press it twice inside a 2 seconds frame, it will turn the LED off at any point
The second press within two seconds of the first? What time frame? What if the LED is off?
You cannot program that which you cannot clearly describe. Perhaps English is not your first language?
You can skip the description and draw a logic chart with the switch and led in the Y axis and time in the X. No translation issues with a diagram. You’ll be amazed how easy it will be to program when you can see the logic directly.
"Perhaps English is not your first language?" -- no, this is what many years of screwing the education budget has done.
Consider that in 1986 the US version of the SAT was dumbed down just to make the scores higher after the effect was noted by critics of the cuts. That's right Howdy Doody fixed the scores and left the schools broken. I've felt sorry for US school kids since 1981, my generation had it good compared.
OP seems to want an activation button that can be cancelled up to 2 seconds after pressing with another press.
Teach about buttons and bounce? Teach about not using delay() and what works instead?