Timer which counts up and down

Hi, Imagine you have 2 buttons. Pressing the first button, then a timer should count up to 10 seconds. If the button is released during these 10 seconds, the timer should remember his condition. Pressing the same button again the timer should proceed with the counting. However, if the other button is pressed, the timer should count down.

How do you solve computationally best? May you tell me the syntax?

Thanks in advance :)

You don't need to use a timer. You simply keep track of the time that events happen (the switch became pressed, the switch became released, etc.) and the current time, to determine if sufficient time has passed.

The possible uses of your system escape me. How to code the system might be different if we know how it was actually to be used, and what the resolution of the system needed to be.

I want to inflate a pad. The pad needs 10 seconds to get full. For example: If 5 seconds pressing the first button and filling the pad are over, I press the other button for 2 seconds, now the timer should count down for the time during the air leaves pad. If I now press the first button again the pad should inflate again and the timer should count up to 10 seconds and the timer should stop then.

thank you greetings alex

Do you know how to read the state of a button ?

Yes sure. With an inputsignal which is high or low.

high -> button is pressed on 5V low -> button is not pressed on GND

How do you solve computationally best?

Why does it matter?
Has your processor got anything else to do?

I don't really know what you mean. We only want a syntax..

By "his condition" did you mean the time remaining from 10 seconds? I sort of see where you're going with this, but you need to use more precise language. The syntax is from C++. By "syntax", do you mean the code?

OK, maybe I misunderstood the question

How do you solve computationally best?

On the timescales of motors and humans pressing switches, does it matter if the motor is turned on/off in a few microseconds or a few milliseconds?

No it doesn't matter.

So, you want to record when the inflate switch (buttons are for shirts) becomes pressed. You want to record when the deflate switch becomes pressed.

On any given pass through loop, you want to see if the pad is being inflated (the inflate start time is non-zero) or deflated (the deflate start time is non-zero). If it is being inflated, has it been being inflated for 10 seconds or more? If so, stop the inflator. If not, keep inflating.

If the pad is being deflated, has it been deflating for the time it was being inflated? If so, stop the deflator.

When the inflate switch becomes pressed, you need to do more, obviously, than record the time. When the deflate switch becomes pressed, you need to to more, obviously, than record the time.

You'll need actions in the "when the deflate switch becomes released" and "when the inflate switch becomes released" cases, too.

But, this should give you enough clues to get something started. Post what you come up with, and explain what it actually does, and how that differs from what you want (if it differs).