We have one motor and one button. When we are push this button for 1 second - servo goes to the one limit position. When we are holding the button over 3 seconds it goes to back to other limit position.
MOST IMPORTANT: in that time while the motor goes, if we are pressing the button it stops.
I will be very happy, if anyone can show me the code (NOT give me 10 links and some recomendations).
Lightsworn:
Can anyone help me with the code for servo motor.
I need the next algorithm:
We have one motor and one button. When we are push this button for 1 second - servo goes to the one limit position. When we are holding the button over 3 seconds it goes to back to other limit position.
MOST IMPORTANT: in that time while the motor goes, if we are pressing the button it stops.
I will be very happy, if anyone can show me the code (NOT give me 10 links and some recomendations).
Thanks to all.
That's a thoroughly ambiguous description of the behaviour you want.
So I press the button continuously, should the motor start moving after
1 second? Should it move only if I release the button between 1 and 3 seconds
after pressing it? If I hold the button down continuously should anything happen?
After all you say that if the motor is moving and the button is down the motion
should immeidately stop... As far as I can make sense of your requirements.
I think it is a partial description of what should happen. I've seen worse than Lightsworn explains.
You should draw your self a "state diagram". From every state there are triggers/event/happenings that take you to the next state. To give you an idea, a few states I think of are:
Motor at beginning& Button up. (from here only a button push causes a state transition)
Motor not moving& button is still down, 1 second timer is running. (exit from this state is either button goes up, timer runs out)
Motor is moving forward, button is still down (humans are soooo slow). So here a button change or the stepper reaches the end (you count how many steps you are doing, right?) are the state change triggers.
Small additional hint/advise: If you use delay() to time the one or three second button push your code will not work. Lots of short delays (for timing the stepper steps) is OK.