timer help

i am a project with function user need to press button a total of 10 sec and led will on .After Led on for 5sec the system will reset and user need press again

Press and hold 10sec LED ON
Press and release and press again LED will still ON if total timing added together is 10sec
LED on for 5sec then off

please help by giving some guidance

You need to record when the switch becomes pressed. The state change detection example, and the millis() function, might be useful.

You need to check, periodically, if the switch is pressed and, if it is, how long it has been pressed. If it has been pressed for long enough, turn the LED on and record when you did that.

You need to check, periodically, if the LED is on, and, if is is, how long it has been on. If it has been on for long enough, turn it off.

None of this is beyond a newbie level.

@OP

Are you trying to say that --

Switch is closed and as long as switch remains closed, the LED remains OFF. Is this statement correct?

If switch gets opened within 10-sec time, the LED becomes ON. Is this statement correct?

If 10-sec time is elapsed with switch at closed condition, the LED becomes ON. Is this statement correct?

Let the LED remain ON for 5-sec; after that, the MCU will automatically be reset; the program will be re-executed from the beginning. Is this statement correct?

GolamMostafa:
@OP

Are you trying to say that --

Switch is closed and as long as switch remains closed, the LED remains OFF. Is this statement correct?

If switch gets opened within 10-sec time, the LED becomes ON. Is this statement correct?

If 10-sec time is elapsed with switch at closed condition, the LED becomes ON. Is this statement correct?

Let the LED remain ON for 5-sec; after that, the MCU will automatically be reset; the program will be re-executed from the beginning. Is this statement correct?

To be more clear

If switch is press and for 10sec (he can press in 1 shot or press,release and press again for total 10 sec)
LED ON
After LED ON for 5sec auto Off and reset the program

Maybe a stopwatch is what you're looking for?

https://forum.arduino.cc/index.php?topic=227029.0

Alextak:
To be more cler
If switch is press and for 10sec (he can press in 1 shot or press,release and press again for total 10 sec)
LED ON

I had a plan to draw a flow chart for the solution of your problem; now, I have difficulties as I don't understand at all what you have stated in the above quote.

GolamMostafa:
I had a plan to draw a flow chart for the solution of your problem; now, I have difficulties as I don't understand at all what you have stated in the above quote.

what I meant is the user can press and hold for 10sec OR
user can press for 1sec and release and press 9sec
user can press for 2sec and release and press 8sec
user can press for 3sec and release and press 7sec
user can press for 4sec and release and press 6sec
user can press for 5sec and release and press 5sec
user can press for 1sec and release and press 2sec and release 7sec
………….
so user can on the LED by pressing the button for 10sec in total

Alextak:
what I meant is the user can press and hold for 10sec OR
user can press for 1sec and release and press 9sec
user can press for 2sec and release and press 8sec
user can press for 3sec and release and press 7sec
user can press for 4sec and release and press 6sec
user can press for 5sec and release and press 5sec
user can press for 1sec and release and press 2sec and release 7sec
………….
so user can on the LED by pressing the button for 10sec in total

User can press switch and hold it for 1 sec; (during this time LED is ON or OFF?)

User then releases (open) the switch and the switch remains open for how long?(Say 2 sec) (during this time LED is ON or OFF?

User then presses switch and hold it for 7 sec (during this time LED is ON or OFF?)

How to do you want to force the MCU to point at the reset vector?

Am I correct when I say the OP want to 'record' the time length of each button press and the total time should not exceed 10 seconds?

GolamMostafa:
User can press switch and hold it for 1 sec; (during this time LED is ON or OFF?)

LED OFF because user need press a total of 10 sec to ON

GolamMostafa:
User then releases (open) the switch and the switch remains open for how long?(Say 2 sec) (during this time LED is ON or OFF?

LED OFF because user need press a total of 10 sec to ON

GolamMostafa:
User then presses switch and hold it for 7 sec (during this time LED is ON or OFF?)

LED ON because user pressed a total of 10sec

GolamMostafa:
How to do you want to force the MCU to point at the reset vector?

led ON for 5sec

Sounds like a retentive timer.

dougp:
Sounds like a retentive timer.

Dougp- you are correct. From what is said above the OP want some sketch on this

fnb111:
Am I correct when I say the OP want to 'record' the time length of each button press and the total time should not exceed 10 seconds?

I also think so; but, the OP is messing around.