Hi Guys, i am new to this, i am writing code for 2 servos , i want servo 1 to move from 40 to 90 degree for 3 mins & once that is done i want Servo 2 to move from 90 to 140 degree for 2 mins.
i want to know how can i set time for 1st servo to run for 3 mins & 2nd servo to run for 2 mins.
You need to respect the forum rules if you want help.
Your question has nothing to do with command line tools. If you had read the sticky post at the top of the forum section, you would have posted your question in a more appropriate section.
You should have used code tags when posting your code. If you had read the forum guide, you would have known this.
I have moved your topic to a more appropriate section. Please edit your post and add those code tags.
Do you want servo 1 to cycle forth and back for 3 minutes or do you want it to cycle just once taking 3 minutes to do so?
Same question for servo 2.
Either way what you need are 2 Boolean flags to indicate the stage of the sequence you are in.
In your declarations add:
bool servo1Done=FALSE;
bool servo2Done=FALSE;
Then in the loop you will need some conditional executions based on those flags:
if servo1Done == FALSE {
Put servo1 activities here. When done you will execute this line:
servo1Done=TRUE;
}
if servo1Done == TRUE && servo2Done == FALSE {. // added “servo1Done == true && “ part
Put servo2 activities here. When done you will execute this line:
servo2Done=TRUE;
}
This is a rough outline of additions to your sketch. There are other ways to do this, such as a state machine. This is just one suggestion to get you thinking along a path.
They are 3, 2 seconds when used with millis() function -- am I correct? Otherwise, the unit/dimension of 3000 in this dclaration: unsigned long msec1 = 3000; could be anything -- cm/inch/m3.