Counting the time while button is pushed

Hello programmers :slight_smile:

I am a new to arduino and i'm wondering, how can i write a program that when you push and hold first button it starts counting the time and after releasing the button it stops and keeps the outcome, and when you push and hold second button it starts counting down that same time. Then i want to use that result of the time for the third button which will work like a switch. When you will just press the third button the program will start doing some orders for the result of the counted time and that time will count down at the same time.
And if you hit the first (or second) button the order of the third button and the counted time will immediately stops and you can hit the first or the second button again and it will starts counting again, down or up depends on which button will be pressed, the first or the second.

I hope i was clear and understandable :).
Please help me with the solution.

You don't "count the time". You record when the switch BECOMES pressed and when it BECOMES released and you compute the time it was pressed. The state change detection example shows how to determine that the switch has become pressed or has become released.

I want to control a motor with that, first PUSH button in one direction, the second in another. First and second PUSH buttons already working like they should. But the third button will be as switch, and will be for control the motor in one of the directions for about 7 sec, but i want that if you push first or second button in the middle of operation, the order of third button will be canceled and arduino will be prepared for other orders.

I tried with delay for 7sec, but of course it doesn't working because the arduino is in the "pause" mode.

Maybe this should work without any counting, but, like you said with state changes and if sentences.

I tried with the state change detection and it working like the buttons are switches, once you press them the motor start working continuously. That's not the way i want. I want the first two buttons to working on the push and just while the button is HIGH. And the third one i want to work for 7 sec and after that the motor is LOW, not HIGH like it is now. And if you press any of two other buttons all is stopped and then you must push it again to work.

Please answer with suggestions, thx