I'm a complete beginner to Arduino and C++ so please be gentle.
The code below works fine if i press but2, LED blinks three times then stops, but if I release but2 and repress LED does not blink because blink is > 3 now.
I want to be able to press but2 multiple times and have it blink the LED three times each time.
How do I create a counter that resets after each button push?
Your posted code is the most simple code to do what you described blink 3 times on first button-press. (but no more)
Your wanted functionality to be able to make the LED blink 3 times on each button-press requires additional lines of code.
As long as you use delay() there is trouble ahead.
For such a supertiny small code delay() is sufficient.
It will work - more or less - for blink three times on each button-press.
But as soon as you go some steps beyond that
using delay() will delay you for hours and days making code that does more than blink an led 3 times.
So even if you think I want a quick solution I recommend that you learn what non-blocking coding is. Especially non-blocking timing.
As soon as you have understood how non-blocking timing works
and
have understood how state-machines work
the world of programming is open to you.
and this will speed-up writing code to be 5 times faster as without it.
So what is your decision:
learning to think linear dead-end-route (for more complex programming)
or
learning non-blocking coding which opens up all possabilities?
(circular most outer looping)
Thanks Stefan and I hear what you are saying.
I will work on understanding nonblocking code, would you recommend using the millis function for nonblocking timing loops?
James